@meecode/ng112-reg-js
v3.0.6
Published
## Table of Contents - [Installation](#Installation) - [Exposed Classes](#exposed-classes) - [Prerequisites](#Prerequisites) - [Usage](#Usage) - [Registration Client](#Registration-Client) - [Initializing the registration client](#initializi
Readme
ng112-reg-js
Table of Contents
- Installation
- Exposed Classes
- Prerequisites
- Usage
- Methods & Properties
- DEC112RegistrationClient
- PhoneVerificationData
- RegistrationData
- RegistrationInformationData
- RequestDataError
- Registration
- DeleteRegistration
- AppConfiguration
- AppServices
- AppService
- RootConfiguration
- Settings
- SettingsInvalidError
- NormalizePhoneNumberData
- NormalizedPhoneNumber
- CheckRegistrationData
- ResendVerificationCode
- RegistrationEndpoint
- CountryRegistrationEndpoint
- RequestError
- RegistrationState
- InAppSearch
- InAppSearchItem
Installation
npm install @meecode/ng112-reg-jsExposed Classes
- DEC112RegistrationClient
- AppConfiguration
- AppServices
- AppService
- App
- DeleteRegistration
- DeleteRegistrationData
- NormalizePhoneNumberData
- NormalizedPhoneNumber
- Notification
- PhoneVerificationData
- Registration
- RegistrationData
- RegistrationInformationData
- RegistrationState
- CheckRegistrationData
- ResendPhoneVerificationCodeData
- ResendVerificationCode
- RequestDataError
- RequestError
- RootConfiguration
- RegistrationEndpoint
- CountryRegistrationEndpoint
- Settings
- SettingsInvalidError
- Service
- EmergencyService
- Message
- Category
- DefaultMessages
- SilentMessages
Prerequisites
- Valid API Key
- Registration service URL
Usage
Be aware that the import syntax depends on the environment you are using
Registration Client
Initializing the registration client
import { DEC112RegistrationClient, Settings } from '@meecode/ng112-reg-js/dist/node';
const registrationServer = 'https://your-registration-server-url/api/apiVersion';
const apiKey = 'yourApiKey';
const settings: Settings = new Settings(registrationServer, apiKey);
const instance = new DEC112RegistrationClient(settings);Register a device
Follow these steps to register a device:
| Parameter | Required | |--------------------------------------------------------------------------------------------------|---------------| | Get root configuration and choose the appropriate registration endpoint | yes | | Normalize phone number | yes | | Register device | yes | | Send verification code | yes | | Resend verification code | no (Optional) | | Get configuration when verification was successful | yes | | Test configuration | no (Optional) |
The registrationId is very important and needs to be stored in order to send other queries. There is no possibility on recover a lost registrationId.
import { RegistrationData, Registration } from '@meecode/ng112-reg-js/dist/node';
const registrationServer = 'https://your-registration-server-url/api/apiVersion';
const apiKey = 'yourApiKey';
const settings: Settings = new Settings(registrationServer, apiKey);
const instance = new DEC112RegistrationClient(settings);
const normalizePhoneNumberData = new NormalizePhoneNumberData('066412345678', '0042');
const response = await instance.normalizePhoneNumber(normalizePhoneNumberData);
const registrationData = new RegistrationData('iPhone XS', 'en', response.normalizedPhoneNumber);
const registrationResponse = await instance.register(registrationData);
const phoneVerificationData = new PhoneVerificationData("4444-1111", registrationResponse.registrationId);
const verifyPhoneResponse = await instance.verifyPhoneNumber(phoneVerificationData);
const registrationInformationData = new RegistrationInformationData(registrationResponse.registrationId);
const deviceConfiguration = await instance.getConfiguration();
Error Handling
Every method returns Readonly<RequestError> in case one or more errors occur.
import { RegistrationData, Registration } from '@meecode/ng112-reg-js/dist/node';
const registrationServer = 'https://your-registration-server-url/api/apiVersion';
const apiKey = 'yourApiKey';
const settings: Settings = new Settings(registrationServer, apiKey);
const instance = new DEC112RegistrationClient(settings);
const registrationData = new RegistrationData('iPhone XS', 'en', '000011112222');
const registrationResponse = instance.register(registrationData)
.catch((error: Readonly<RequestError>) => {
//TODO: implement
});Usage in combination with ng112-js SDK
Query the app configuration after successful registration
import {
Agent,
DEC112Specifics,
} from 'ng112-js/dist/node';
const registrationServer = 'https://your-registration-server-url/api/apiVersion';
const apiKey = 'yourApiKey';
const settings: Settings = new Settings(registrationServer, apiKey);
const instance = new DEC112RegistrationClient(settings);
const registrationInformationData = new RegistrationInformationData('registrationId');
const configuration = await instance.getConfiguration(registrationInformationData);
const agenConfiguration = {
endpoint: configuration.server,
domain: configuration.realm,
user: configuration.privateId,
password: configuration.password,
displayName: 'Your display name',
namespaceSpecifics: new DEC112Specifics(undefined, configuration.registrationId, 'your language')
};
const agent = new Agent(agenConfiguration);
// Choose the appropriate service from the array of available services and use the sip property as conversation partner
const conversationPartner = configuration.services.default[0].sip;
agent.createConversation(conversationPartner);Methods & Properties
DEC112RegistrationClient
The DEC112RegistrationClient is used to communicate with the corresponding registration service.
Constructor
constructor(settings)
| Parameter | Type | Default | Required | Description |
|-----------|-------------------------|---------|----------|-------------------------------------------|
| settings | Settings | null | yes | Settings used for initializing the client |
UpdateRegistrationServer
Update the registration server
updateRegistrationServer(registrationServer)
| Parameter | Type | Default | Required | Description |
|--------------------|----------|---------|----------|--------------|
| registrationServer | string | null | yes | |
GetConfiguration
Get the configuration for an already existing registration. The configuration can change, so it is recommended to check periodically if the configuration has changed.
getConfiguration(registrationInfo)
| Parameter | Type | Default | Required | Description |
|-------------------------|---------------------------------------------------------------|---------|----------|--------------|
| registrationInformation | RegistrationInformationData | null | yes | |
Returns a Promise which resolves with Readonly<AppConfiguration> when successful and rejects
with Readonly<RequestError> when an error occurred.
GetRootConfiguration
The root configuration provides a list of DEC112 registries and other resources (e.g. language resources). Select the registry which should be used for the registration process.
getRootConfiguration()
No parameters required.
Returns a Promise which resolves with Readonly<RootConfiguration> when successful and rejects
with Readonly<RequestError> when an error occurred.
NormalizePhoneNumber
normalizePhoneNumber(phoneNumberData)
| Parameter | Type | Default | Required | Description |
|------------------|----------------------------------------------------------|---------|-----------|---------------|
| phoneNumberData | NormalizePhoneNumberData | null | true | |
Returns a Promise which resolves with Readonly<NormalizedPhoneNumber> when
successful and rejects with Readonly<RequestError> when an error occurred.
Register
Register a new user with the given registration information.
register(registrationData)
| Parameter | Type | Default | Required | Description |
|------------------|-----------------------------------------|---------|----------|--------------|
| registrationData | RegistrationData | null | yes |
Returns a Promise which resolves with Readonly<Registration> when successful and rejects
with Readonly<RequestError> when an error occurred.
CheckRegistration
Check the registration data of an existing registration. Can also be used to check the registration state (e.g.: pending, ...)
Returns a Promise which resolves with Readonly<Registration> when successful and rejects
with Readonly<RequestError> when an error occurred.
ResendPhoneVerificationCode
Allows resending a possibly lost phone verification SMS code up to two times.
resendPhoneVerificationCode(rendCodeData)
| Parameter | Type | Default | Required | Description |
|----------------|------------------------------------------------------------------------|---------|----------|--------------|
| resendCodeData | ResendPhoneVerificationCodeData | null | true | |
Returns a Promise which resolves with Readonly<ResendVerificationCode> when successful and
rejects with Readonly<RequestError> when an error occurred.
Unregister
Deletes an existing Registration.
unregister(deleteRegistrationData)
| Parameter | Type | Default | Required | Description |
|------------------------|-----------------------------------------------------|---------|----------|--------------|
| deleteRegistrationData | DeleteRegistrationData | null | true | |
Returns a Promise which resolves with Readonly<DeleteRegistration> when successful and rejects
with Readonly<RequestError> when an error occurred.
VerifyPhoneNumber
Verifies a registrations phone number.
verifyPhoneNumber(verificationData)
| Parameter | Type | Default | Required | Description |
|------------------|---------------------------------------------------|---------|----------|--------------|
| verificationData | PhoneVerificationData | null | true | |
Returns a Promise which resolves with Readonly<Registration> when successful and rejects
with Readonly<RequestError> when an error occurred.
EnableDebug
Enables the debug mode which outputs also debug statements to the console.
enableDebug(true)
| Parameter | Type | Default | Required | Description |
|-----------|---------|---------|----------|--------------|
| enabled | boolean | null | true | |
IsDebugEnabled
Checks whether the debug mode is enabled or not.
isDebugEnabled()
PhoneVerificationData
| Property | Type | Default | Required | Description |
|------------------|----------|---------|----------|--------------|
| verificationCode | string | null | yes | |
| registrationId | string | null | yes | |
RegistrationData
| Property | Type | Default | Required | Description |
|-------------|----------|---------|----------|--------------|
| model | string | null | no | |
| language | string | null | yes | |
| phoneNumber | string | null | yes | |
SaveRegistrationData
| Property | Type | Default | Required | Description |
|----------------|----------|---------|----------|--------------|
| registrationId | string | null | yes | |
| phoneNumber | string | null | yes | |
| data | object | null | yes | |
RegistrationInformationData
| Property | Type | Default | Required | Description |
|----------------|----------|---------|----------|---------------------------------------------------------------------------------|
| registrationId | string | null | yes | The registration id of the device which the configuration should be queried for |
DeleteRegistrationData
| Property | Type | Default | Required | Description |
|----------------|----------| --- |----------|--------------|
| registrationId | string | null | yes | |
| phoneNumber | string | null | yes | |
RequestDataError
| Property | Type | Default | Required | Description | |----------|------|---------|----------|--------------|
Registration
| Property | Type | Description |
|----------------------------|-------------------------------------------|--------------|
| registrationId | string | |
| language | string | |
| state | RegistrationState | |
| phoneVerificationTimeStamp | string | |
| phonePrivacy | string | |
| registrationTimeStamp | string | |
DeleteRegistration
| Property | Type | Description |
|----------------|----------|--------------|
| registrationId | string | |
AppConfiguration
Response of getConfiguration request
| Property | Type | Description |
|----------------|-------------------------------|--------------|
| registrationId | string | |
| server | string | |
| publicId | string | |
| privateId | string | |
| password | string | |
| realm | string | |
| services | AppServices | |
AppServices
| Property | Type | Description |
|----------|---------------------|---------------------------------------------------------------------------------------|
| service | Service | A Service element containing all available emergency services information |
| app | App | A list of AppService elements used for test emergency calls |
RootConfiguration
| Property | Type | Description |
|--------------------------|----------------------------------------------------------------------|--------------|
| countryRegistryEndpoints | Array<CountryRegistrationEndpoint> | |
Settings
| Property | Type | Default | Required | Description |
|--------------------|----------|----------|----------|-----------------------------------|
| registrationServer | string | null | yes | |
| apiKey | string | string | yes | The api key used for verification |
SettingsInvalidError
| Property | Type | Default | Required | Description |
|----------|------------------------------------------------|---------|----------|--------------|
| errors | Array<RequestDataError> | null | yes | |
NormalizePhoneNumberData
| Property | Type | Default | Required | Description |
|-------------------|----------|---------|----------|----------------------------------|
| phoneNumber | string | null | yes | |
| phoneNumberPrefix | string | null | yes | The prefix for the phone number. | 0043 |
NormalizedPhoneNumber
| Property | Type | Default | Required | Description | Example(s) |
|-----------------------|----------|---------|----------|--------------|------------|
| phoneNumber | string | null | true | |
| normalizedPhoneNumber | string | null | true | |
| code | string | null | true | |
CheckRegistrationData
| Property | Type | Default | Required | Description | Example(s) |
|----------------|----------|---------|----------|--------------|------------|
| registrationId | string | null | true | |
ResendPhoneVerificationCodeData
Response of ResendPhoneVerificationCode request.
| Property | Type | Description |
|----------------|----------|--------------|
| registrationId | string | |
ResendVerificationCode
Request data for the ResendPhoneVerificationCode request.
| Property | Type | Default | Required | Description |
|----------------|----------|---------|----------|--------------|
| registrationId | string | null | yes |
RegistrationEndpoint
| Property | Type | Description |
|----------|----------|--------------|
| type | string | |
| baseUrl | string | |
CountryRegistrationEndpoint
| Property | Type | Description |
|-----------------------|--------------------------------------------------------|--------------|
| name | string | |
| registrationEndpoints | Array<RegistrationEndpoint> | |
RequestError
| Property | Type | Description |
|------------|----------|--------------|
| message | string | |
| value | string | |
| identifier | string | |
RegistrationState
Enum for the different registration states. Every value between 2 - 8 means ongoing verification process.
| Value | Integer Value | Description | |---------------------|---------------|-------------| | notRegistered | 0 | | | pendingRegistration | 1 | | | registrationError | 9 | | | registered | 10 | |
Service
Emergency service configuration
| Property | Type | Description |
|-----------|---------------------------|-------------------------------------------------------|
| services | Array<EmergencyService> | A list of EmergencyService items |
| message | Message | A Message object |
| category | Category | A Message object |
EmergencyService
| Property | Type | Description |
|------------|-----------------|----------------------------------------------------------|
| in | string | Unique id for the server |
| enabled | boolean | A value indicating whether the service is enabled or not |
| title | Translations | A Translations object |
| category | string | |
| urn | string | |
| sip | string | |
| icon | string | |
| type | string | |
| titleShort | Translations | A Translations object |
Message
| Property | Type | Description |
|-----------------|-------------------|---------------------------------------------------|
| defaultMessages | DefaultMessages | A DefaultMessages object |
| silentMessages | SilentMessages | A SilentMessages object |
Category
| Property | Type | Description |
|-----------|---------------------|--------------------------------------------------|
| emergency | EmergencyCategory | A EmergencyCategory object |
| test | TestCategory | A TestCategory object |
DefaultMessages
| Property | Type | Description |
|------------|-----------------|-------------------------------------------------------------------------------------------------------|
| start | Translations | The start message for an emergency call. A Translation object |
| stop | Translations | The stop message for an emergency call. A Translation object |
| background | Translations | The message when the device is sent to background. A Translation object |
| foreground | Translations | The message when the device is sent to foreground. A Translation object |
| internal | Translations | An internal message not intended to be sent to the call center. A Translation object |
SilentMessages
| Property | Type | Description |
|-----------|-----------------|---------------------------------------------------------------------------------------|
| start | Translations | The start message for a silent emergency call. A Translation object |
EmergencyCategory
| Property | Type | Description |
|----------|----------------|---------------------------------------|
| title | Translations | A Translation object |
TestCategory
| Property | Type | Description |
|----------|----------------|---------------------------------------|
| title | Translations | A Translation object |
Translations
Translations object
| Property | Type | Description |
|----------|----------|---------------------------|
| en | string | English translation text |
| de | string | German translation text |
App
App specific configuration
| Property | Type | Description |
|-----------------|----------------|--------------------------------------|
| notification | Notification | Notification object |
| environmentType | string | Current values: DEC112 or undefined |
Notification
Notification specific configuration
| Property | Type | Description |
|---------------|----------|-------------|
| appIdentifier | string | |
InAppSearch
| Property | Type | Description |
|----------------|--------------------------|-------------|
| emergencyCalls | Array<InAppSearchItem> | |
InAppSearchItem
| Property | Type | Description |
|-------------|----------------------|-------------|
| id | string | |
| title | Translation | |
| description | Translation | |
| domain | string | |
| keywords | Array<Translation> | |
Author
Special Thanks
For supporting the development:
License
UNLICENSED
Copyright
Copyright © 2021 - 2022, MeeCode by Mario Murrent. All Rights Reserved.
