@smartcloud/compliance
v2.5.61
Published
Common Compliance code and type definitions
Downloads
953
Keywords
Readme
SmartCloud Compliance SDK
Installation
It is recommended to use the latest version of this SDK. To install:
npm install @smartcloud/compliance@latest
Getting started
To intialise the client, either apiSecret
or a tokenGetter
function must be supplied in order to be authenticated.
const client = new ComplianceClient(config);
Configuration:
interface ComplianceBaseConfig {
basePath: string; // SmartCloud API base path
apiKey: string; // Your SmartCloud API key
// Optional override for getting user
user?: {
id: string; // Your SmartCloud user ID
email?: string;
name?: string;
alias?: string; // Your name alias
}
// At least one of either
apiSecret: string; // Your SmartCloud API secret
tokenGetter: () => Promise<string>; // Getter function to get your Firebase Token periodically
}
Features
Cases
To access cases from an organization.
const cases = client.cases(orgId);
Cases returned by the SDK are wrapped in a Case
class with unique features depending on the type of case
Get cases by modification date
Cases returned are ordered where the most recently updated case is returned first.
const caseStream = cases.getCasesByModification({ latest: Date.now(), oldest: 0, fullCase: false });
caseStream.on('data', (caseList) => {
// Do something with case list
});
caseStream.on('end', () => {
// Finished
});
Get cases by creation date
Cases returned are ordered where the most recent case is returned first.
const caseStream = cases.getCasesByCreation({ latest: Date.now(), oldest: 0, fullCase: false });
caseStream.on('data', (caseList) => {
// Do something with case list
});
caseStream.on('end', () => {
// Finished
});
Get cases by URI
Get up to 40 cases by URI
const caseList = await cases.getCasesByURI(['uri1', 'uri2', 'uri3'], fullCase: false);
Case
The case class can be used to directly modify a case and/or it's events. Currently the only supported case type is Parking
, though a generic class can be used to manage custom cases. Supported cases may have unique methods or handle specific use cases differently
Event getters
Getter methods for specific known event types are available
- Metadata
getMetadataEvent
- Case ID
getCaseIdEvent
- Cancel
getCancelledEvent
- Close
getClosedEvent
- Breach
getBreachEvent
- Breach Appeal
getBreachAppealEvents
- Breach Reminder
getBreachReminder
Additionally, you may get a specific event through these methods:
- Get event by type:
const event = await case.getEventByType(type);
- Get event by ID:
const event = await case.getEventById(eventId);
Case Updaters
Updater methods can be used to update case metadata information.
Methods: assignOfficer updateGroups updateSiteLocation updateLocation addNotes editNotes deleteNotes updatePriority
Case Actions
Actions can be taken upon a case that may result in changing it's state or events.
Methods: issueBreach closeCase openCase cancelCase
🚘 Parking Case
Methods: getParkingSessionEvent
Parking Session Event
Methods: getOffenses getParkingSessionVersion
Events
Each case may have multiple events which hold specific data relating to that event type
Methods: updateEvent Event.createUnpublished
To publish a new event to a case:
const event = await case.postNewEvent(newEvent);
Similarly, an event can also be deleted from a case:
await case.deleteEvents(eventIds);
Example Code
const cases = client.cases('org1');
const myCase = await cases.createCase<ParkingCase>('Parking', [{
type: 'Metadata',
data: {
groups: ['org1#org1', 'org1#region1', 'region1#site1'],
metadata: {
location: {
latitude: 0,
longitude: 0,
openLocationCode: 'xxxxx',
}
priority: 1,
}
}
}
]);
await myCase.addNotes({ text: 'My first note' });
const metadataEvent = myCase.getMetadataEvent();
await metadataEvent.updateEvent({
...metadataEvent.data,
metadata: {
...metadataEvent.metadata,
custom: {
foo: 'bar',
}
}
}
);
await myCase.closeCase('special-circumstance');
Compliance Configuration
To access compliance configuration for an organization:
const configuration = await client.configuration(orgId);
Methods: getConfig addConfig updateConfig deleteConfig addCatalog deleteCatalog toJSON
Configurations hold an array of grouped configurations. Each grouped configuration also contains an array of sub group configurations. Currently the only supported configuration is Parking
. However, generic configurations can also be managed.
const parkingConfig = configuration.getConfig({ type: 'Parking' });
// full config JSON object including absent property values
const object = parkingConfig.toJSON();
Group Config
Currently only the Parking
and Animal
configuration types are supported. However, generic configurations can also be managed.
🚘 Parking Configuration
Methods: getTicketTemplate getTicketTemplateData
Getter methods are supplied for known catalog types
- Policies (Time based overstay, no payment, payment overstay)
- Vehicle Makes
- Vehicle Types
- Vehicle States
- Vehicle Colours
- Bay Types
- Substates
- Substate Triggers
- Trigger Actions
- Common Notes
- Cancel Reasons
- Close Reasons