2.0.4 • Published 2 months ago

@meecode/ng112-reg-js v2.0.4

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

ng112-reg-js

Table of Contents

Installation

npm install @meecode/ng112-reg-js

Exposed Classes

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:

ParameterRequired
Get root configuration and choose the appropriate registration endpointyes
Normalize phone numberyes
Register deviceyes
Send verification codeyes
Resend verification codeno (Optional)
Get configuration when verification was successfulyes
Test configurationno (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('066475007205', '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)

ParameterTypeDefaultRequiredDescription
settingsSettingsnullyesSettings used for initializing the client

UpdateRegistrationServer

Update the registration server

updateRegistrationServer(registrationServer)

ParameterTypeDefaultRequiredDescription
registrationServerstringnullyes

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)

ParameterTypeDefaultRequiredDescription
registrationInformationRegistrationInformationDatanullyes

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)

ParameterTypeDefaultRequiredDescription
phoneNumberDataNormalizePhoneNumberDatanulltrue

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)

ParameterTypeDefaultRequiredDescription
registrationDataRegistrationDatanullyes

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)

ParameterTypeDefaultRequiredDescription
resendCodeDataResendPhoneVerificationCodeDatanulltrue

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)

ParameterTypeDefaultRequiredDescription
deleteRegistrationDataDeleteRegistrationDatanulltrue

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)

ParameterTypeDefaultRequiredDescription
verificationDataPhoneVerificationDatanulltrue

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)

ParameterTypeDefaultRequiredDescription
enabledbooleannulltrue

IsDebugEnabled

Checks whether the debug mode is enabled or not.

isDebugEnabled()

PhoneVerificationData

PropertyTypeDefaultRequiredDescription
verificationCodestringnullyes
registrationIdstringnullyes

RegistrationData

PropertyTypeDefaultRequiredDescription
modelstringnullno
languagestringnullyes
phoneNumberstringnullyes

SaveRegistrationData

PropertyTypeDefaultRequiredDescription
registrationIdstringnullyes
phoneNumberstringnullyes
dataobjectnullyes

RegistrationInformationData

PropertyTypeDefaultRequiredDescription
registrationIdstringnullyesThe registration id of the device which the configuration should be queried for

DeleteRegistrationData

PropertyTypeDefaultRequiredDescription
registrationIdstringnullyes
phoneNumberstringnullyes

RequestDataError

PropertyTypeDefaultRequiredDescription

Registration

PropertyTypeDescription
registrationIdstring
languagestring
stateRegistrationState
phoneVerificationTimeStampstring
phonePrivacystring
registrationTimeStampstring

DeleteRegistration

PropertyTypeDescription
registrationIdstring

AppConfiguration

Response of getConfiguration request

PropertyTypeDescription
registrationIdstring
serverstring
publicIdstring
privateIdstring
passwordstring
realmstring
servicesAppServices

AppServices

PropertyTypeDescription
serviceServiceA Service element containing all available emergency services information
appAppA list of AppService elements used for test emergency calls

RootConfiguration

PropertyTypeDescription
countryRegistryEndpointsArray<CountryRegistrationEndpoint>

Settings

PropertyTypeDefaultRequiredDescription
registrationServerstringnullyes
apiKeystringstringyesThe api key used for verification

SettingsInvalidError

PropertyTypeDefaultRequiredDescription
errorsArray<RequestDataError>nullyes

NormalizePhoneNumberData

PropertyTypeDefaultRequiredDescription
phoneNumberstringnullyes
phoneNumberPrefixstringnullyesThe prefix for the phone number.0043

NormalizedPhoneNumber

PropertyTypeDefaultRequiredDescriptionExample(s)
phoneNumberstringnulltrue
normalizedPhoneNumberstringnulltrue
codestringnulltrue

CheckRegistrationData

PropertyTypeDefaultRequiredDescriptionExample(s)
registrationIdstringnulltrue

ResendPhoneVerificationCodeData

Response of ResendPhoneVerificationCode request.

PropertyTypeDescription
registrationIdstring

ResendVerificationCode

Request data for the ResendPhoneVerificationCode request.

PropertyTypeDefaultRequiredDescription
registrationIdstringnullyes

RegistrationEndpoint

PropertyTypeDescription
typestring
baseUrlstring

CountryRegistrationEndpoint

PropertyTypeDescription
namestring
registrationEndpointsArray<RegistrationEndpoint>

RequestError

PropertyTypeDescription
messagestring
valuestring
identifierstring

RegistrationState

Enum for the different registration states. Every value between 2 - 8 means ongoing verification process.

ValueInteger ValueDescription
notRegistered0
pendingRegistration1
registrationError9
registered10

Service

Emergency service configuration

PropertyTypeDescription
servicesArray<EmergencyService>A list of EmergencyService items
messageMessageA Message object
categoryCategoryA Message object

EmergencyService

PropertyTypeDescription
instringUnique id for the server
enabledbooleanA value indicating whether the service is enabled or not
titleTranslationsA Translations object
categorystring
urnstring
sipstring
iconstring
typestring
titleShortTranslationsA Translations object

Message

PropertyTypeDescription
defaultMessagesDefaultMessagesA DefaultMessages object
silentMessagesSilentMessagesA SilentMessages object

Category

PropertyTypeDescription
emergencyEmergencyCategoryA EmergencyCategory object
testTestCategoryA TestCategory object

DefaultMessages

PropertyTypeDescription
startTranslationsThe start message for an emergency call. A Translation object
stopTranslationsThe stop message for an emergency call. A Translation object
backgroundTranslationsThe message when the device is sent to background. A Translation object
foregroundTranslationsThe message when the device is sent to foreground. A Translation object
internalTranslationsAn internal message not intended to be sent to the call center. A Translation object

SilentMessages

PropertyTypeDescription
startTranslationsThe start message for a silent emergency call. A Translation object

EmergencyCategory

PropertyTypeDescription
titleTranslationsA Translation object

TestCategory

PropertyTypeDescription
titleTranslationsA Translation object

Translations

Translations object

PropertyTypeDescription
enstringEnglish translation text
destringGerman translation text

App

App specific configuration

PropertyTypeDescription
notificationNotificationNotification object
environmentTypestringCurrent values: DEC112 or undefined

Notification

Notification specific configuration

PropertyTypeDescription
appIdentifierstring

InAppSearch

PropertyTypeDescription
emergencyCallsArray<InAppSearchItem>

InAppSearchItem

PropertyTypeDescription
idstring
titleTranslation
descriptionTranslation
domainstring
keywordsArray<Translation>

Author

MeeCode by Mario Murrent

Special Thanks

For supporting the development:

Gebsl

License

UNLICENSED

Copyright

Copyright © 2021 - 2023, MeeCode by Mario Murrent. All Rights Reserved.

CI Status

Node.js CI

2.0.30-beta

2 months ago

2.0.29-beta

2 months ago

2.0.28-beta

3 months ago

2.0.27-beta

3 months ago

2.0.26-beta

4 months ago

2.0.25-beta

4 months ago

2.0.14-beta

6 months ago

2.0.11-beta

6 months ago

2.0.22-beta

6 months ago

2.0.8-beta

7 months ago

2.0.6-beta

7 months ago

2.0.19-beta

6 months ago

2.0.23-beta

5 months ago

2.0.18-beta

6 months ago

2.0.15-beta

6 months ago

2.0.13-beta

6 months ago

2.0.24-beta

5 months ago

2.0.21-beta

6 months ago

2.0.16-beta

6 months ago

2.0.9-beta

6 months ago

2.0.5-beta

7 months ago

2.0.20-beta

6 months ago

2.0.12-beta

6 months ago

2.0.17-beta

6 months ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.4

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.2.17

3 years ago

0.2.16

3 years ago

0.2.15

3 years ago

0.2.14

3 years ago

0.2.13

3 years ago

0.2.12

3 years ago

0.2.11

3 years ago

0.2.10

3 years ago

0.2.7

3 years ago

0.2.9

3 years ago

0.2.8

3 years ago

0.2.6

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.3

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.2.2

3 years ago

0.1.19

3 years ago

0.1.18

3 years ago

0.1.17

3 years ago

0.1.16

3 years ago

0.1.15

3 years ago

0.1.14

3 years ago

0.1.13

3 years ago

0.1.12

3 years ago

0.1.11

3 years ago

0.1.10

3 years ago

0.1.9

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago