@elevated-libs/cuss2
Advanced tools
Comparing version 2.0.95 to 2.1.0
{ | ||
"name": "@elevated-libs/cuss2", | ||
"version": "2.0.95", | ||
"version": "2.1.0", | ||
"description": "", | ||
@@ -18,3 +18,3 @@ "main": "dist/index.js", | ||
"@types/node": "^14.17.32", | ||
"@elevated-libs/cuss2-javascript-models": "1.0.1", | ||
"@elevated-libs/cuss2-typescript-models": "1.0.2", | ||
"events": "^3.3.0", | ||
@@ -21,0 +21,0 @@ "rxjs": "^7.5.2", |
@@ -5,3 +5,3 @@ # @elevated-libs/cuss2 | ||
Interact with a CUSS 2.0 Restful API using a simple interface leveraging the asyncronicity of event driven architectures. By using the Elevated CUSS library you will get: | ||
Interact with a CUSS 2 API using a simple interface leveraging the asyncronicity of event driven architectures. By using the Elevated CUSS library you will get: | ||
@@ -12,5 +12,5 @@ - Simple device interfaces | ||
CUSS [(Common Use Self-Service)](https://en.wikipedia.org/wiki/Common-use_self-service) is a modern Typescript library facilitating application development of Self-Service check-in apps, self-tagging apps and self bag-drop apps. | ||
CUSS [(Common Use Self-Service)](https://www.iata.org/en/programs/passenger/common-use/#tab-2) is a modern Typescript library facilitating application development of Self-Service check-in apps, self-tagging apps and self bag-drop apps. | ||
You can have CUSS 2.0 NOW and run a modern browser entirely without plugins or Java. Finally, your Information Security department will be able to sign off on your CUSS applications. | ||
You can have CUSS 2 NOW and run a modern browser entirely without plugins or Java. Finally, your Information Security department will be able to sign off on your CUSS applications. | ||
@@ -21,3 +21,3 @@ We have also created typescript angular and react libs facilitating rapid development of CUSS applications. | ||
- Typescript libs for [Angular](https://github.com/elevationsoftware/cuss2-angular) and [React](https://github.com/elevationsoftware/cuss2-react) | ||
- Typescript libs for [Angular](https://github.com/elevationsoftware/cuss2-docs/blob/master/angular/README.md) and [React](https://github.com/elevationsoftware/cuss2-docs/blob/master/react/README.md) | ||
@@ -152,3 +152,3 @@ | ||
// query ATB | ||
// query component | ||
const res: PlatformData = await cuss2?.barcodeReader.query(); | ||
@@ -211,1 +211,26 @@ | ||
| Keypad | A component that provides keypad input. | | ||
#### Card Reader | ||
Besides inheriting from all the Media Input methods, the library provides an automatic way to setup a card reader component to read ISO track data without truncation. This feature is only available on Platforms data provide a card reader component interface on CUSS 2 Platforms. The magtripe capabilities are officcially removed from CUSS 2 specification. | ||
```ts | ||
const cuss2 = await Cuss2.connect(cuss2URL, clientId, clientSecret); | ||
// query component | ||
const res: PlatformData = await cuss2?.cardReader.query(); | ||
// validate component state | ||
if (res.meta.componentState !== ComponentState.READY) { | ||
console.log('Component is not ready') | ||
} else { | ||
// Enable component for ISO track data, for 10 secs then automatically disable the device | ||
await cuss2.cardReader.readPayment(5000); | ||
// Subscribe to MEDIA_PRESENT | ||
cuss2.cardReader.data.asObservable().subscribe((data: DataRecordList) => { | ||
console.log(`card Reader Data ${data}`); | ||
}); | ||
} | ||
``` |
@@ -1,2 +0,2 @@ | ||
import { StatusCodes } from 'cuss2-javascript-models'; | ||
import { MessageCodes } from '@elevated-libs/cuss2-typescript-models'; | ||
import { | ||
@@ -9,3 +9,3 @@ ComponentCharacteristics, | ||
MediaTypes | ||
} from "cuss2-javascript-models"; | ||
} from "@elevated-libs/cuss2-typescript-models"; | ||
@@ -71,3 +71,3 @@ export { EnvironmentComponent, MediaTypes }; | ||
if (!charac0) return; | ||
return dsTypesHas(charac0, CUSSDataTypes.KEY) && dsTypesHas(charac0, CUSSDataTypes.KEY_UP) && dsTypesHas(charac0, CUSSDataTypes.KEY_DOWN); | ||
return dsTypesHas(charac0, CUSSDataTypes.KEY) && dsTypesHas(charac0, CUSSDataTypes.KEYUP) && dsTypesHas(charac0, CUSSDataTypes.KEYDOWN); | ||
} | ||
@@ -82,3 +82,3 @@ | ||
static isHeadset = (component:EnvironmentComponent) => { | ||
if (component.componentType !== ComponentTypes.MEDIA_INPUT) return; | ||
if (component.componentType !== ComponentTypes.MEDIAINPUT) return; | ||
const charac0 = component.componentCharacteristics?.[0]; | ||
@@ -91,3 +91,3 @@ if (!charac0) return; | ||
static isScale = (component:EnvironmentComponent) => { | ||
if (component.componentType !== ComponentTypes.DATA_INPUT) return; | ||
if (component.componentType !== ComponentTypes.DATAINPUT) return; | ||
const charac0 = component.componentCharacteristics?.[0]; | ||
@@ -105,3 +105,3 @@ if (!charac0) return; | ||
static isCamera = (component: EnvironmentComponent) => { | ||
if (component.componentType !== ComponentTypes.DATA_INPUT) return; | ||
if (component.componentType !== ComponentTypes.DATAINPUT) return; | ||
const charac0 = component.componentCharacteristics?.[0]; | ||
@@ -108,0 +108,0 @@ if (!charac0) return; |
import {EventEmitter} from 'events' | ||
import {ApplicationData} from "cuss2-javascript-models" | ||
import {ApplicationData} from "@elevated-libs/cuss2-typescript-models" | ||
import {helpers} from "./helper.js"; | ||
@@ -178,4 +178,4 @@ import {PlatformResponseError} from "./models/platformResponseError.js"; | ||
return promise.then(message => { | ||
const statusCode = message.meta.statusCode; | ||
if (helpers.isNonCritical(statusCode)) { | ||
const messageCode = message.meta.messageCode; | ||
if (helpers.isNonCritical(messageCode)) { | ||
return message; | ||
@@ -182,0 +182,0 @@ } else { |
@@ -8,3 +8,3 @@ | ||
import {ComponentInterrogation} from "./componentInterrogation.js"; | ||
import { ApplicationStateCodes } from 'cuss2-javascript-models'; | ||
import { ApplicationActivationExecutionModeEnum, ApplicationStateCodes } from '@elevated-libs/cuss2-typescript-models'; | ||
import { | ||
@@ -39,7 +39,7 @@ Announcement, | ||
ApplicationStateChangeReasonCodes as ChangeReason | ||
} from "cuss2-javascript-models"; | ||
} from "@elevated-libs/cuss2-typescript-models"; | ||
export { ApplicationStateCodes, DataRecordList }; | ||
const ExecutionModeEnum = ApplicationActivation.ExecutionModeEnum | ||
const ExecutionModeEnum = ApplicationActivationExecutionModeEnum | ||
@@ -329,3 +329,3 @@ const { | ||
this.componentStateChange.next(component); | ||
if (this._online && (unsolicited || meta.platformDirective === PlatformDirectives.peripheralsQuery)) { | ||
if (this._online && (unsolicited || meta.platformDirective === PlatformDirectives.PeripheralsQuery)) { | ||
this.checkRequiredComponentsAndSyncState(); | ||
@@ -352,3 +352,3 @@ } | ||
getEnvironment: async (): Promise<EnvironmentLevel> => { | ||
const ad = Build.applicationData(PlatformDirectives.platformEnvironment) | ||
const ad = Build.applicationData(PlatformDirectives.PlatformEnvironment) | ||
const response = await this.connection.sendAndGetResponse(ad) | ||
@@ -369,3 +369,3 @@ log('verbose', '[getEnvironment()] response', response); | ||
getComponents: async (): Promise<ComponentList> => { | ||
const ad = Build.applicationData(PlatformDirectives.platformComponents) | ||
const ad = Build.applicationData(PlatformDirectives.PlatformComponents) | ||
const response = await this.connection.sendAndGetResponse(ad) | ||
@@ -427,3 +427,3 @@ log('verbose', '[getComponents()] response', response); | ||
getStatus: async (componentID:number): Promise<PlatformData> => { | ||
const ad = Build.applicationData(PlatformDirectives.peripheralsQuery, {componentID}) | ||
const ad = Build.applicationData(PlatformDirectives.PeripheralsQuery, {componentID}) | ||
const response = await this.connection.sendAndGetResponse(ad) | ||
@@ -445,3 +445,3 @@ log('verbose', '[queryDevice()] response', response); | ||
send: async (componentID:number, dataObj:DataRecordList): Promise<PlatformData> => { | ||
const ad = Build.applicationData(PlatformDirectives.peripheralsSend, { | ||
const ad = Build.applicationData(PlatformDirectives.PeripheralsSend, { | ||
componentID, | ||
@@ -465,3 +465,3 @@ dataObj | ||
validateComponentId(componentID); | ||
const ad = Build.applicationData(PlatformDirectives.peripheralsSetup, { | ||
const ad = Build.applicationData(PlatformDirectives.PeripheralsSetup, { | ||
componentID, | ||
@@ -484,3 +484,3 @@ dataObj | ||
validateComponentId(componentID); | ||
const ad = Build.applicationData(PlatformDirectives.peripheralsCancel, {componentID}) | ||
const ad = Build.applicationData(PlatformDirectives.PeripheralsCancel, {componentID}) | ||
return await this.connection.sendAndGetResponse(ad) | ||
@@ -500,3 +500,3 @@ }, | ||
validateComponentId(componentID); | ||
const ad = Build.applicationData(PlatformDirectives.peripheralsUserpresentEnable, {componentID}) | ||
const ad = Build.applicationData(PlatformDirectives.PeripheralsUserpresentEnable, {componentID}) | ||
return await this.connection.sendAndGetResponse(ad) | ||
@@ -516,3 +516,3 @@ }, | ||
validateComponentId(componentID); | ||
const ad = Build.applicationData(PlatformDirectives.peripheralsUserpresentDisable, {componentID}) | ||
const ad = Build.applicationData(PlatformDirectives.PeripheralsUserpresentDisable, {componentID}) | ||
return await this.connection.sendAndGetResponse(ad) | ||
@@ -522,3 +522,3 @@ }, | ||
validateComponentId(componentID); | ||
const ad = Build.applicationData(PlatformDirectives.peripheralsUserpresentOffer, {componentID}) | ||
const ad = Build.applicationData(PlatformDirectives.PeripheralsUserpresentOffer, {componentID}) | ||
return await this.connection.sendAndGetResponse(ad) | ||
@@ -583,7 +583,7 @@ }, | ||
validateComponentId(componentID); | ||
const dataObj = DataRecordList.constructFromObject([{ | ||
const dataObj = [{ | ||
data: rawData as any, | ||
dsTypes: [ CUSSDataTypes.SSML ] | ||
}]) | ||
const ad = Build.applicationData(PlatformDirectives.peripheralsAnnouncementPlay, { | ||
}] | ||
const ad = Build.applicationData(PlatformDirectives.PeripheralsAnnouncementPlay, { | ||
componentID, dataObj | ||
@@ -599,3 +599,3 @@ }) | ||
validateComponentId(componentID); | ||
const ad = Build.applicationData(PlatformDirectives.peripheralsAnnouncementPause, {componentID}) | ||
const ad = Build.applicationData(PlatformDirectives.PeripheralsAnnouncementPause, {componentID}) | ||
return await this.connection.sendAndGetResponse(ad) | ||
@@ -609,3 +609,3 @@ }, | ||
validateComponentId(componentID); | ||
const ad = Build.applicationData(PlatformDirectives.peripheralsAnnouncementResume, {componentID}) | ||
const ad = Build.applicationData(PlatformDirectives.PeripheralsAnnouncementResume, {componentID}) | ||
return await this.connection.sendAndGetResponse(ad) | ||
@@ -619,3 +619,3 @@ }, | ||
validateComponentId(componentID); | ||
const ad = Build.applicationData(PlatformDirectives.peripheralsAnnouncementStop, {componentID}) | ||
const ad = Build.applicationData(PlatformDirectives.PeripheralsAnnouncementStop, {componentID}) | ||
return await this.connection.sendAndGetResponse(ad) | ||
@@ -796,4 +796,4 @@ } | ||
export {Connection} from "./connection.js"; | ||
export * from "cuss2-javascript-models"; | ||
export * from "@elevated-libs/cuss2-typescript-models"; | ||
export * from "./helper.js"; | ||
export * from "./componentInterrogation.js"; |
@@ -5,17 +5,8 @@ import {Subject} from "rxjs"; | ||
ApplicationData, | ||
ApplicationDataPayload, | ||
ApplicationDataMeta, | ||
ApplicationState, | ||
ApplicationTransfer, | ||
DataRecordList, | ||
ScreenResolution, | ||
IlluminationData, | ||
BaggageData, | ||
CommonUsePaymentMessage, | ||
CommonUseBiometricMessage, | ||
StatusCodes, | ||
PlatformDirectives | ||
} from "cuss2-javascript-models"; | ||
MessageCodes, | ||
PlatformDirectives, | ||
ApplicationDataPayload | ||
} from "@elevated-libs/cuss2-typescript-models"; | ||
export { StatusCodes }; | ||
@@ -58,3 +49,3 @@ export class LogMessage { | ||
*/ | ||
isNonCritical: (status:StatusCodes) => { | ||
isNonCritical: (messageCode:MessageCodes) => { | ||
return !criticalErrors.some(s => s == status) | ||
@@ -70,44 +61,54 @@ } | ||
const criticalErrors = [ | ||
StatusCodes.CANCELLED, | ||
StatusCodes.WRONG_STATE, | ||
StatusCodes.OUT_OF_SEQUENCE, | ||
StatusCodes.TIMEOUT, | ||
StatusCodes.SESSION_TIMEOUT, | ||
StatusCodes.KILL_TIMEOUT, | ||
StatusCodes.SOFTWARE_ERROR, | ||
StatusCodes.CRITICAL_SOFTWARE_ERROR, | ||
StatusCodes.CONFIGURATION_ERROR, | ||
StatusCodes.FORMAT_ERROR, | ||
StatusCodes.LENGTH_ERROR, | ||
StatusCodes.DATA_MISSING, | ||
StatusCodes.THRESHOLD_ERROR, | ||
StatusCodes.THRESHOLD_USAGE, | ||
StatusCodes.HARDWARE_ERROR, | ||
StatusCodes.NOT_REACHABLE, | ||
StatusCodes.NOT_RESPONDING, | ||
StatusCodes.BAGGAGE_FULL, | ||
StatusCodes.BAGGAGE_UNDETECTED, | ||
StatusCodes.BAGGAGE_OVERSIZED, | ||
StatusCodes.BAGGAGE_TOO_MANY_BAGS, | ||
StatusCodes.BAGGAGE_UNEXPECTED_BAG, | ||
StatusCodes.BAGGAGE_TOO_HIGH, | ||
StatusCodes.BAGGAGE_TOO_LONG, | ||
StatusCodes.BAGGAGE_TOO_FLAT, | ||
StatusCodes.BAGGAGE_TOO_SHORT, | ||
StatusCodes.BAGGAGE_INVALID_DATA, | ||
StatusCodes.BAGGAGE_WEIGHT_OUT_OF_RANGE, | ||
StatusCodes.BAGGAGE_JAMMED, | ||
StatusCodes.BAGGAGE_EMERGENCY_STOP, | ||
StatusCodes.BAGGAGE_RESTLESS, | ||
StatusCodes.BAGGAGE_TRANSPORT_BUSY, | ||
StatusCodes.BAGGAGE_MISTRACKED, | ||
StatusCodes.BAGGAGE_UNEXPECTED_CHANGE, | ||
StatusCodes.BAGGAGE_INTERFERENCE_USER, | ||
StatusCodes.BAGGAGE_INTRUSION_SAFETY, | ||
StatusCodes.BAGGAGE_NOT_CONVEYABLE, | ||
StatusCodes.BAGGAGE_IRREGULAR_BAG, | ||
StatusCodes.BAGGAGE_VOLUME_NOT_DETERMINABLE, | ||
StatusCodes.BAGGAGE_OVERFLOW_TUB | ||
MessageCodes.CANCELLED, | ||
MessageCodes.WRONGAPPLICATIONSTATE, | ||
MessageCodes.OUTOFSEQUENCE, | ||
MessageCodes.TIMEOUT, | ||
MessageCodes.SESSIONTIMEOUT, | ||
MessageCodes.KILLTIMEOUT, | ||
MessageCodes.SOFTWAREERROR, | ||
MessageCodes.CRITICALSOFTWAREERROR, | ||
MessageCodes.FORMATERROR, | ||
MessageCodes.LENGTHERROR, | ||
MessageCodes.DATAMISSING, | ||
MessageCodes.THRESHOLDERROR, | ||
MessageCodes.THRESHOLDUSAGE, | ||
MessageCodes.HARDWAREERROR, | ||
MessageCodes.NOTREACHABLE, | ||
MessageCodes.NOTRESPONDING, | ||
MessageCodes.BAGGAGEFULL, | ||
MessageCodes.BAGGAGEUNDETECTED, | ||
MessageCodes.BAGGAGEOVERSIZED, | ||
MessageCodes.BAGGAGETOOMANYBAGS, | ||
MessageCodes.BAGGAGEUNEXPECTEDBAG, | ||
MessageCodes.BAGGAGETOOHIGH, | ||
MessageCodes.BAGGAGETOOLONG, | ||
MessageCodes.BAGGAGETOOFLAT, | ||
MessageCodes.BAGGAGETOOSHORT, | ||
MessageCodes.BAGGAGEINVALIDDATA, | ||
MessageCodes.BAGGAGEWEIGHTOUTOFRANGE, | ||
MessageCodes.BAGGAGEJAMMED, | ||
MessageCodes.BAGGAGEEMERGENCYSTOP, | ||
MessageCodes.BAGGAGERESTLESS, | ||
MessageCodes.BAGGAGETRANSPORTBUSY, | ||
MessageCodes.BAGGAGEMISTRACKED, | ||
MessageCodes.BAGGAGEUNEXPECTEDCHANGE, | ||
MessageCodes.BAGGAGEINTERFERENCEUSER, | ||
MessageCodes.BAGGAGEINTRUSIONSAFETY, | ||
MessageCodes.BAGGAGENOTCONVEYABLE, | ||
MessageCodes.BAGGAGEIRREGULARBAG, | ||
MessageCodes.BAGGAGEVOLUMENOTDETERMINABLE, | ||
MessageCodes.BAGGAGEOVERFLOWTUB | ||
] | ||
const isDataRecord = (dataRecordObject: any) => { | ||
if ( Array.isArray(dataRecordObject) && dataRecordObject.length > 0 ) { | ||
const first = dataRecordObject[0]; | ||
if (first.hasOwnProperty('data')) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
export const Build = { | ||
@@ -117,3 +118,3 @@ applicationData: (directive, options={}) => { | ||
const {componentID, token, dataObj} = options | ||
const meta = new ApplicationDataMeta() | ||
const meta = {} as ApplicationDataMeta | ||
meta.requestID = uuid.v4() | ||
@@ -124,13 +125,14 @@ meta.oauthToken = token | ||
const payload = new ApplicationDataPayload() | ||
if(dataObj instanceof ApplicationState) { payload.applicationState = dataObj } | ||
if(dataObj instanceof ApplicationTransfer) { payload.applicationTransfer = dataObj } | ||
if(dataObj instanceof DataRecordList) { payload.dataRecords = dataObj } | ||
if(dataObj instanceof ScreenResolution) { payload.screenResolution = dataObj } | ||
if(dataObj instanceof IlluminationData) { payload.illuminationData = dataObj } | ||
if(dataObj instanceof BaggageData) { payload.bagdropData = dataObj } | ||
if(dataObj instanceof CommonUsePaymentMessage) { payload.paymentData = dataObj } | ||
if(dataObj instanceof CommonUseBiometricMessage) { payload.biometricData = dataObj } | ||
const payload = {} as ApplicationDataPayload | ||
if(dataObj.hasOwnProperty('applicationStateCode')) { payload.applicationState = dataObj } | ||
if(dataObj.hasOwnProperty('targetApplicationID')) { payload.applicationTransfer = dataObj } | ||
if(isDataRecord(dataObj)) { payload.dataRecords = dataObj } | ||
if(dataObj.hasOwnProperty('verticak')) { payload.screenResolution = dataObj } | ||
if(dataObj.hasOwnProperty('lightColor')) { payload.illuminationData = dataObj } | ||
if(dataObj.hasOwnProperty('baggageMeasurements')) { payload.bagdropData = dataObj } | ||
if(dataObj.hasOwnProperty('ePaymentMessage')) { payload.paymentData = dataObj } | ||
if(dataObj.hasOwnProperty('biometricProviderMessage')) { payload.biometricData = dataObj } | ||
const ad = new ApplicationData(meta) | ||
const ad = {} as ApplicationData | ||
ad.meta = meta | ||
ad.payload = payload | ||
@@ -140,4 +142,4 @@ return ad | ||
stateChange: (desiredState, reasonCode, reason, brand=undefined) => { | ||
return Build.applicationData(PlatformDirectives.platformApplicationsStaterequest, { | ||
dataObj: ApplicationState.constructFromObject({ | ||
return Build.applicationData(PlatformDirectives.PlatformApplicationsStaterequest, { | ||
dataObj: { | ||
applicationStateCode: desiredState, | ||
@@ -147,5 +149,5 @@ applicationStateChangeReasonCode: reasonCode, | ||
applicationBrand: brand | ||
}) | ||
} | ||
}) | ||
} | ||
} |
@@ -1,3 +0,3 @@ | ||
export * from "cuss2-javascript-models"; | ||
export * from "@elevated-libs/cuss2-typescript-models"; | ||
export * from './cuss2.js' | ||
export * from './models/component.js' |
@@ -9,6 +9,7 @@ import {BehaviorSubject, combineLatest, Subject} from "rxjs"; | ||
ComponentState, | ||
IlluminationDataLightColor, | ||
CUSS2IlluminationdomainIlluminationDataLightColor, | ||
PlatformData, | ||
StatusCodes | ||
} from "cuss2-javascript-models"; | ||
MessageCodes, | ||
PlatformDirectives | ||
} from "@elevated-libs/cuss2-typescript-models"; | ||
import {DeviceType} from './deviceType.js'; | ||
@@ -26,3 +27,3 @@ import {PlatformResponseError} from "./platformResponseError.js"; | ||
* @property {boolean} required - Whether the component is required to be connected to the CUSS Platform. | ||
* @property {BehaviorSubject<StatusCodes>} statusChanged - Observable that emits the status of the component on changes. | ||
* @property {BehaviorSubject<messageCodes>} statusChanged - Observable that emits the status of the component on changes. | ||
* @property {DeviceType} deviceType - The type of device the component is, *See IATA documentation for more details. | ||
@@ -81,3 +82,3 @@ * @property {number} pendingCalls - The number of pending calls to the component. | ||
required: boolean = false; | ||
statusChanged: BehaviorSubject<StatusCodes> = new BehaviorSubject<StatusCodes>(StatusCodes.OK); | ||
statusChanged: BehaviorSubject<MessageCodes> = new BehaviorSubject<MessageCodes>(MessageCodes.OK); | ||
_componentState: ComponentState = ComponentState.UNAVAILABLE; | ||
@@ -110,9 +111,9 @@ deviceType: DeviceType; | ||
* @typeof Getter | ||
* @returns {StatusCodes} the status of the component | ||
* @returns {MessageCodes} the status of the component | ||
*/ | ||
get status(): StatusCodes { return this.statusChanged.getValue(); } | ||
get status(): MessageCodes { return this.statusChanged.getValue(); } | ||
constructor(component: EnvironmentComponent, cuss2: Cuss2, _type: DeviceType = DeviceType.UNKNOWN) { | ||
this._component = component; | ||
this.id = component.componentID as number; | ||
this.id = Number(component.componentID); | ||
this.deviceType = _type; | ||
@@ -123,3 +124,3 @@ Object.defineProperty(this, 'api', { | ||
}); | ||
cuss2.onmessage.subscribe((data:PlatformData) => { | ||
cuss2.onmessage.subscribe((data: PlatformData) => { | ||
if (data?.meta?.componentID === this.id) { | ||
@@ -136,4 +137,4 @@ this._handleMessage(data); | ||
const name = this.deviceType; | ||
const parentId = Math.min(this.id, ...component.linkedComponentIDs); | ||
if(parentId != this.id) { | ||
const parentId = Math.min(this.id, ...component.linkedComponentIDs as number[]); | ||
if (parentId != this.id) { | ||
this.parent = cuss2.components[parentId] | ||
@@ -150,3 +151,3 @@ // feeder and dispenser are created in the printer component | ||
stateIsDifferent(msg: PlatformData): boolean { | ||
return this.status !== msg.meta.statusCode || this._componentState !== msg.meta.componentState; | ||
return this.status !== msg.meta.messageCode || this._componentState !== msg.meta.componentState; | ||
} | ||
@@ -168,4 +169,4 @@ | ||
if (this.status !== meta.statusCode) { | ||
this.statusChanged.next(meta.statusCode); | ||
if (this.status !== meta.messageCode) { | ||
this.statusChanged.next(meta.messageCode); | ||
} | ||
@@ -177,3 +178,3 @@ } | ||
const poll = () => { | ||
if (this.ready && (!requireOK || this.status === StatusCodes.OK)) { | ||
if (this.ready && (!requireOK || this.status === MessageCodes.OK)) { | ||
return this._poller = undefined; | ||
@@ -233,3 +234,3 @@ } | ||
.catch((e:PlatformResponseError) => { | ||
if (e.statusCode === StatusCodes.OUT_OF_SEQUENCE) { | ||
if (e.messageCode === MessageCodes.OUTOFSEQUENCE) { | ||
this.enabled = false; | ||
@@ -311,3 +312,3 @@ return e; | ||
this.onmessage.next(data); | ||
if (data?.meta?.statusCode === StatusCodes.DATA_PRESENT && data?.payload?.dataRecords?.length) { | ||
if (data?.meta?.messageCode === MessageCodes.DATAPRESENT && data?.payload?.dataRecords?.length) { | ||
this.previousData = data?.payload?.dataRecords?.map((dr:DataRecord) => dr?.data); | ||
@@ -439,3 +440,3 @@ this.data.next(this.previousData) | ||
* @property {Subject<boolean>} combinedReadyStateChanged - The combined ready state of this printer, feeder, and dispenser; emits true when ready. | ||
* @property {BehaviorSubject<StatusCodes>} combinedStatusChanged - The combined status of this printer, feeder, and dispenser; emits on status code changes. | ||
* @property {BehaviorSubject<messageCodes>} combinedStatusChanged - The combined status of this printer, feeder, and dispenser; emits on status code changes. | ||
@@ -463,3 +464,3 @@ * @example | ||
const missingLink = (msg:string) => { throw new Error(msg); }; | ||
const linked = component.linkedComponentIDs?.map(id => cuss2.components[id] as Component) || []; | ||
const linked = component.linkedComponentIDs?.map(id => cuss2.components[id as number] as Component) || []; | ||
@@ -498,4 +499,4 @@ this.feeder = linked.find(c => c instanceof Feeder) || missingLink('Feeder not found for Printer ' + this.id); | ||
]) | ||
.subscribe((statuses: StatusCodes[]) => { | ||
const status = statuses.find(s => s != StatusCodes.OK) || StatusCodes.OK; | ||
.subscribe((statuses: MessageCodes[]) => { | ||
const status = statuses.find(s => s != MessageCodes.OK) || MessageCodes.OK; | ||
if (this.combinedStatus !== status) { | ||
@@ -506,3 +507,3 @@ this._combinedStatus = status; | ||
}); | ||
this.combinedStatusChanged = new BehaviorSubject<StatusCodes>(StatusCodes.OK); | ||
this.combinedStatusChanged = new BehaviorSubject<MessageCodes>(MessageCodes.OK); | ||
} | ||
@@ -513,5 +514,5 @@ | ||
combinedReadyStateChanged: Subject<boolean> = new Subject<boolean>(); | ||
combinedStatusChanged: BehaviorSubject<StatusCodes> = new BehaviorSubject<StatusCodes>(StatusCodes.OK); | ||
combinedStatusChanged: BehaviorSubject<MessageCodes> = new BehaviorSubject<MessageCodes>(MessageCodes.OK); | ||
_superStatusChanged: BehaviorSubject<StatusCodes>; | ||
_superStatusChanged: BehaviorSubject<MessageCodes>; | ||
_superReadyStateChanged: Subject<boolean>; | ||
@@ -544,8 +545,8 @@ | ||
_combinedStatus = StatusCodes.OK; | ||
_combinedStatus = MessageCodes.OK; | ||
/** | ||
* @typeof - Getter | ||
* @returns {StatusCodes} - The combined status of the printer, feeder, and dispenser. | ||
* @returns {MessageCodes} - The combined status of the printer, feeder, and dispenser. | ||
*/ | ||
get combinedStatus(): StatusCodes { | ||
get combinedStatus(): MessageCodes { | ||
return this._combinedStatus; | ||
@@ -557,11 +558,11 @@ } | ||
// Unfortunately, it briefly considers the Printer to be UNAVAILABLE. | ||
if (msg.functionName === 'send' && msg.statusCode === StatusCodes.TIMEOUT && msg.componentState === ComponentState.UNAVAILABLE) { | ||
msg.componentState = ComponentState.READY; | ||
if (msg.meta.platformDirective === PlatformDirectives.PeripheralsSend && msg.meta.messageCode === MessageCodes.TIMEOUT && msg.meta.componentState === ComponentState.UNAVAILABLE) { | ||
msg.meta.componentState = ComponentState.READY; | ||
} | ||
// if now ready, query linked components to get their latest status | ||
if (!this.ready && msg.componentState === ComponentState.READY) { | ||
if (!this.ready && msg.meta.componentState === ComponentState.READY) { | ||
this.feeder.query().catch(console.error); | ||
this.dispenser.query().catch(console.error); | ||
} | ||
else if (msg.statusCode === StatusCodes.MEDIA_PRESENT) { | ||
else if (msg.meta.messageCode === MessageCodes.MEDIAPRESENT) { | ||
this.dispenser.mediaPresentChanged.next(true); | ||
@@ -572,4 +573,4 @@ // query the dispenser- which will start a poller that will detect when the media has been taken | ||
if (this.status !== msg.statusCode) { | ||
this.statusChanged.next(msg.statusCode); | ||
if (this.status !== msg.meta.messageCode) { | ||
this.statusChanged.next(msg.meta.messageCode); | ||
} | ||
@@ -631,5 +632,6 @@ const rsc = this.combinedReadyStateChanged; | ||
const dx = (r:string) => DataRecordList.constructFromObject([ | ||
{ data: (r || '') as any, dsTypes: dsTypes } | ||
]); | ||
const dx = (r:string) => [{ | ||
data: r as any, | ||
dsTypes: dsTypes | ||
}] | ||
@@ -641,3 +643,6 @@ return await Promise.all(rawArray.map(r => this.api.setup(this.id, dx(r)))) | ||
async sendRaw(raw: string, dsTypes: Array<CUSSDataTypes> = [ CUSSDataTypes.ITPS ] ) { | ||
const dataRecords = DataRecordList.constructFromObject([{ data: (raw || '') as any, dsTypes: dsTypes }]); | ||
const dataRecords =[{ | ||
data: raw as any, | ||
dsTypes: dsTypes | ||
}]; | ||
return this.api.send(this.id, dataRecords); | ||
@@ -788,3 +793,3 @@ } | ||
this.statusChanged.subscribe((status) => { | ||
if (status === StatusCodes.MEDIA_PRESENT) { | ||
if (status === MessageCodes.MEDIAPRESENT) { | ||
this.pollUntilReady(true, 2000); | ||
@@ -823,5 +828,5 @@ if (!this.mediaPresent) { | ||
super._handleMessage(message); | ||
if (message.componentID !== this.id) return; | ||
if (message.meta.componentID !== this.id) return; | ||
const dataRecords = message.dataRecords; | ||
const dataRecords = message.payload.dataRecords; | ||
if (dataRecords?.length) { | ||
@@ -917,3 +922,3 @@ const data = dataRecords.map(dr => dr.data); | ||
// @ts-ignore | ||
let name = (typeof color === 'string')? (IlluminationDataLightColor.NameEnum)[color] : undefined; | ||
let name = (typeof color === 'string')? (CUSS2IlluminationdomainIlluminationDataLightColor.NameEnum)[color] : undefined; | ||
let rgb = (Array.isArray(color) && color.length === 3)? {red:color[0], green:color[1], blue:color[2]} : undefined; | ||
@@ -920,0 +925,0 @@ let blinkRate = (Array.isArray(blink) && blink.length === 2)? {durationOn:blink[0], durationOff:blink[1]} : undefined; |
import { | ||
ComponentState, | ||
PlatformData, | ||
RequestID, | ||
StatusCodes | ||
} from "cuss2-javascript-models"; | ||
UniqueID, | ||
MessageCodes | ||
} from "@elevated-libs/cuss2-typescript-models"; | ||
export class PlatformResponseError extends Error { | ||
constructor(pd:PlatformData) { | ||
super('Platform returned status code: ' + pd.meta.statusCode); | ||
this.componentID = pd.meta.componentID; | ||
super('Platform returned status code: ' + pd.meta.messageCode); | ||
this.componentID = pd.meta.componentID as number; | ||
this.componentState = pd.meta.componentState; | ||
this.requestID = pd.meta.requestID; | ||
this.statusCode = pd.meta.statusCode || StatusCodes.SOFTWARE_ERROR; | ||
this.messageCode = pd.meta.messageCode || MessageCodes.SOFTWAREERROR; | ||
} | ||
componentID?:number; | ||
componentState: ComponentState; | ||
requestID:RequestID; | ||
statusCode: StatusCodes; | ||
requestID:UniqueID; | ||
messageCode: MessageCodes; | ||
} |
@@ -1,2 +0,2 @@ | ||
import {ApplicationStateCodes} from "cuss2-javascript-models"; | ||
import {ApplicationStateCodes} from "@elevated-libs/cuss2-typescript-models"; | ||
@@ -3,0 +3,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1852134
420
15169
231
3