Connection to the UnityBase server (for asynchronous client like Node.js or Browser)

In case host set to value other than location.host server must be configured to accept CORS requests. This is usually done by setting "HTTPAllowOrigin" server configuration option.

Recommended way to create a UBConnection is UB.connect method

  
      // !! In most case UB.connect should be used to create a connection !!
 // But can be created directly, for example in case of multiple connection from one page
 const UB = require('@ubitybase/ub-pub')
 const UBConnection = UB.UBConnection
 // connect using UBIP schema
 let conn = new UBConnection({
   host: 'http://127.0.0.1:888',
   requestAuthParams: function(conn, isRepeat){
     if (isRepeat){
       throw new UB.UBAbortError('invalid credential')
     } else {
       return Promise.resolve({authSchema: 'UBIP', login: 'admin'})
     }
   }
 })
 conn.query({entity: 'uba_user', method: 'select', fieldList: ['ID', 'name']}).then(UB.logDebug)

 // Anonymous connect. Allow access to entity methods, granted by ELS rules to `Anonymous` role
 // Request below will be success if we grant a `ubm_navshortcut.select` to `Anonymous` on the server side
 let conn = new UBConnection({
   host: 'http://127.0.0.1:8888'
 })
 conn.query({entity: 'ubm_navshortcut', method: 'select', fieldList: ['ID', 'name']}).then(UB.logDebug)

 //subscribe to events
 conn.on('authorizationFail', function(reason){
   // indicate user credential is wrong
 })
 conn.on('authorized', function(ubConnection, session, authParams){console.debug(arguments)} )
UBConnection mixes an EventEmitter, so you can subscribe for {@link event:authorized authorized}
and {@link event:authorizationFail authorizationFail} events.
  
Mixes In:

# new UBConnection (connectionParamsobject)

Arguments:
  • connectionParams: object
    • hoststring

      UnityBase server host

    • appName='/'string

      UnityBase application to connect to (obsolete)

    • requestAuthParamsauthParamsCallback

      Auth parameters callback

    • request2farequest2faCallback

      Second factor request callback

    • protocolstring

      either 'https' or 'http' (default)

    • allowSessionPersistentboolean

      See connect for details

    • defHeadersobject

      XHR request headers, what will be added to each xhr request for this connection (after adding headers from UB.xhr.defaults). Object keys is header names. Example: {"X-Tenant-ID": "12"}

    connection parameters

Members

# appConfig : Object instance

Application settings transferred form a server

# appName : string instance

UB application name

# baseURL : string instance

The base of all urls of your requests. Will be prepended to all urls while call UB.xhr

# defHeaders : object instance

Additional headers what will be added to each XHR request

# domain : UBDomain instance

Domain information. Initialized after promise, returned by function getDomainInfo is resolved

# HMAC_SHA256 instance

Calc HMAC_SHA256 from key and string

var shaAsSting = UB.connection.HMAC_SHA256('secretKey', 'something').toString()

# lastLoginName : string instance

Last successful login name. Filled AFTER first 401 response

# preferredLocale : string instance

The preferred (used in previous user session if any or a default for application) locale

# recorderEnabled : boolean instance

Set it to true for memorize all requests to recordedXHRs array (for debug only!)

# serverUrl : string instance

UB Server URL with protocol and host

# SHA256 instance

Calc SHA256 from string

var shaAsSting = UB.connection.SHA256('something').toString()

# ubNotifier : UBNotifierWSProtocol instance

WebSocket ubNotifier protocol instance

Methods

# addNew (serverRequestobject) → Promise.<object> instance

Promise of running UBQL command with addNew method (asynchronously).

Response "data" is an array of default values for row.

Two difference from UBConnection.query:

  • ubRequest.method set to 'addnew'
  • requests is always buffered in the 20ms period into one ubql call
  • Date & 'DateTime' entity attributes are converted from ISO8601 text representation to javaScript Date object

Arguments:
  
      $App.connection.addNew({entity: 'uba_user', fieldList: ['*']}).then(UB.logDebug)
// [{"entity":"uba_user","fieldList":["ID","isPending"],"method":"addnew",
//   "resultData":{"fields":["ID","isPending"],"rowCount": 1, "data":[[332462711046145,0]]}
// }]
  

# addNewAsObject (serverRequestobject, fieldAliasesoptObject.<string, string>) → Promise.<object> instance

Promise of running UBQL command with addNew method (asynchronously).

Result is Object with default values for row.

Arguments:
  • serverRequest: object

    Request to execute

  • fieldAliases: Object.<string, string>

    Optional object to change attribute names during transform array to object. Keys are original names, values - new names

  
      $App.connection.addNewAsObject({"entity":"uba_user"}).then(UB.logDebug)
 // result is {ID: 332462709833729, isPending: false}
  

# authorize (isRepeatoptboolean) → Promise.<UBSession> instance

The starter method for all authorized requests to UB server. Return authorization promise resolved to UBSession. In case unauthorized:

  • call requestAuthParams method passed to UBConnection constructor to retrieve user credentials
  • call UBConnection#doAuth method

Used inside UBConnection#xhr, therefore developer rarely call it directly

Return:

Resolved to {UBSession} if auth success or rejected to {errMsg: string, errCode: number, errDetails: string} if fail

Arguments:
  • isRepeat: boolean

    in case user provide wrong credential - we must show logon window

# cacheClearAll () → Promise instance

Clear all local cache (indexedDB session & permanent and UBConnection.cachedSessionEntityRequested)

# cacheKeyCalculate (rootstring, attributesoptArray.<string>) → string instance

Calculate cache key for request. This key is used to store data inside UBCache

Arguments:
  • root: string

    This is usually entity name

  • attributes: Array.<string>

    if present - add attributes hash. This is usually array of entity attributes we want to put inside cache

# cacheOccurrenceRefresh (rootstring, cacheTypeUBCache.cacheTypes) → Promise instance

Refresh all cache occurrence for root depending on cacheType:

Arguments:

# cacheOccurrenceRemove (rootstring, cacheTypestring) → Promise instance

Remove all cache occurrence for root depending on cacheType:

Arguments:

# checkChannelEncryption (sessionUBSession, cfgobject) → boolean instance

Arguments:

# convertResponseDataToJsTypes (serverResponse) → * instance

Convert raw server response data to javaScript data according to attribute types. Called by UBConnection#select Currently only Data/DateTime & boolean conversion done If resultLock present - resultLock.lockTime also converted

Arguments:
  • serverResponse:
  
      // convert all string representation of date/dateTime to Date object, integer representation of bool to Boolean
return me.query({entity: 'my_entity', method: 'select'}, true)
  .then(me.convertResponseDataToJsTypes.bind(me))
  

# doDelete (serverRequestobject, allowBufferoptboolean) → Promise instance

Promise of running UBQL command with delete method (asynchronously). Difference from UBConnection.query:

  • ubRequest.method set to 'delete' by default
  • if necessary it will clear cache

Arguments:
  • serverRequest: object

    Request to execute

  • allowBuffer: boolean

    Default - false. Allow several "in the same time" request to be buffered to one transaction.

  
      $App.connection.doDelete({
   entity: 'uba_user', fieldList: ['ID','name'], execParams: {ID: 1, name:'newName'}
 }).then(UB.logDebug)
  

# doFilterAndSort (cachedDataTubCachedData, ubqlUBQL) → object instance

Call a LocalDataStore#doFilterAndSort - see a parameters there

Arguments:

# emitEntityChanged (entityCodestring, payloadobject) instance

Emit ${entityCode}:changed event. In case entity has a unity mixin - emit also for unityEntity

Arguments:
  • entityCode: string
  • payload: object

    An object with at last {entity: 'entityCode', method: 'entityMethod', resultData: {} } attributes

# get (urlstring, configoptobject) → Promise.<XHRResponse> instance

The same as UB.get but with authorization

Return:

Future object

Arguments:
  • url: string

    Relative or absolute URL specifying the destination of the request

  • config: object

    optional configuration object - see UB.xhr

  
      // call entity method using rest syntax
const certResp = await UB.connection.get('/rest/uba_usercertificate/getCertificate?ID=334607980199937')
const certBin = certResp.data
  

# getAppInfo () → Promise instance

Retrieve application information. Usually this is first method developer must call after create connection

Return:

Promise resolved to result of getAppInfo method

# getDocument (paramsobject, optionsoptobject) → Promise instance

Retrieve content of document type attribute field from server. Usage samples:

Return:

Resolved to document content (either ArrayBuffer in case options.resultIsBinary===true or text/json)

Arguments:
  • params: object
    • entitystring

      Code of entity to retrieve from

    • attributestring

      document type attribute code

    • idnumber

      Instance ID

    • forceMimestring

      If passed and server support transformation from source MIME type to forceMime server perform transformation and return document representation in the passed MIME

    • revisionnumber

      Optional revision of the document (if supported by server-side store configuration). Default is current revision.

    • fileNamestring

      For dirty document should be passed - getDocument endpoint uses this file extension to create a correct Content-Type header.

      If not passed - dirty document returned with Content-Type: application/octet-stream. For non-dirty documents Content-Type retrieved from JSON in DB.

    • isDirtyboolean

      Optional ability to retrieve document in dirty state

    • storestring

      ????

  • options: object
    • resultIsBinaryboolean

      if true - return document content as ArrayBuffer

    • bypassCacheboolean

      HTTP POST verb will be used instead of GET for bypass browser cache

    Additional request options

  
      //Retrieve content of document as string using GET
 $App.connection.getDocument({
     entity:'ubm_form',
     attribute: 'formDef',
     ID: 100000232003
  }).then(function(result){console.log(typeof result)}); // string

 //The same, but using POST for bypass cache
 $App.connection.getDocument({
     entity:'ubm_form',
     attribute: 'formDef',
     ID: 100000232003
  }, {
     bypassCache: true
  }).then(function(result){console.log(typeof result)}); // string

 //Retrieve content of document as ArrayBuffer and bypass cache
 $App.connection.getDocument({
     entity:'ubm_form',
     attribute: 'formDef',
     ID: 100000232003
  }, {
     bypassCache: true, resultIsBinary: true
  }).then(function(result){
     console.log('Result is', typeof result, 'of length' , result.byteLength, 'bytes'); //output: Result is ArrayBuffer of length 2741 bytes
     let uiArr = new Uint8Array(result) // view into ArrayButter as on the array of byte
     console.log('First byte of result is ', uiArr[0])
  })
  

# getDocumentURL (paramsobject) → Promise.<string> instance

Get a http link to the "Document" attribute content which is valid for the duration of the user session.

This link can be used, for example, in HTML tag and so on.

Used in $App.downloadDocument method to download a BLOB content and in FileRenderer Vue component to display a BLOB content in browser.

Return:

Document URL (valid for the duration of the user session)

Arguments:
  • params: object
    • entitystring

      Code of entity to retrieve from

    • attributestring

      document type attribute code

    • IDnumber

      Instance ID

    • revisionnumber

      Revision of the document. We strongly recommend to pass this argument for correct HTTP cache work

    • isDirtyboolean

      Set it to true to retrieve a document in dirty state

    • fileNamestring

      For dirty document should be passed - getDocument endpoint uses this file extension to create a correct Content-Type header. If not passed - dirty document returned with Content-Type: application/octet-stream.

  
      //Retrieve content of document as string using GET
 const docURL = await UB.connection.getDocumentURL({
     entity:'ubm_form',
     attribute: 'formDef',
     ID: 100000232003,
     revision: 22,
  })
  // result is alike "/getDocument?entity=ubm_form&attribute=formDef&ID=100000232003&revision=22&session_signature=cbe83ece60126ee4a20d40c2"
  

# getDomainInfo () → Promise instance

Retrieve domain information from server. Promise resolve instance of UBDomain

# getPreferredUData (userNameoptstring) → object | undefined instance

Return preferred uData (stored in localStorage for specified user). Preferred uData passed as prefUData URL param during /auth handshake and can be used in server-side Session.on('login') handler

Arguments:
  • userName: string

    if not passed - localStorage.LAST_LOGIN is used (if sets)

# insert (serverRequestobject, allowBufferoptboolean) → Promise instance

Promise of running UnityBase UBQL command with insert method (asynchronously). Difference from UBConnection.query:

  • ubRequest.method set to 'insert'
  • Date & 'DateTime' entity attributes are converted from ISO8601 text representation to javaScript Date object
  • if necessary it will clear cache

Arguments:
  • serverRequest: object

    Request to execute

  • allowBuffer = false: boolean

    Allow several "in the same time" request to be buffered to one transaction.

  
      $App.connection.insert({
   entity: 'uba_user', fieldList: ['ID','name'], execParams: {ID: 1, name:'newName'}
 }).then(UB.logDebug);
  

# insertAsObject (serverRequestobject, fieldAliasesoptObject.<string, string>, allowBufferoptboolean) → Promise.<object> instance

Promise of running UnityBase UBQL command with insert method (asynchronously).

In case fieldList is passed - result will contains new values for attributes specified in fieldList as Object, otherwise - null

Arguments:
  • serverRequest: object
    • entitystring

      Entity to execute the method

    • method='insert'string

      Method of entity to executed

    • fieldListArray.<string>

      Attributes to be returned in result

    • execParamsobject

      Attributes values to be inserted. If ID is omitted it will be autogenerated

    • optionsobject

    • lockTypestring

    • alsNeedboolean

    Request to execute

  • fieldAliases: Object.<string, string>

    Optional object to change attribute names during transform array to object. Keys are original names, values - new names

  • allowBuffer = false: boolean

    Allow several "in the same time" request to be buffered to one transaction.

  
      $App.connection.insertAsObject({
  entity:"uba_user",
  fieldList:['ID', 'name', 'mi_modifyDate'],
  execParams: {name: 'insertedName'}
}).then(UB.logDebug)
  // {ID: 332462911062017, mi_modifyDate: Tue Apr 23 2019 17:04:30 GMT+0300 (Eastern European Summer Time), name: "insertedname"}
  

# isAuthorized () → boolean instance

Is user currently logged in. There is no guaranty what session actually exist in server

# logout (reasonParamsoptobject) instance

Log out user from server

Arguments:

# pki () → Promise.<UbPkiInterface> instance

Inject encryption implementation and return a promise to object what implements a UbPkiInterface

# post (urlstring, data*, configoptobject) → Promise.<XHRResponse> instance

The same as UB.post but with authorization

Return:

Future object

Arguments:
  • url: string

    Relative or absolute URL specifying the destination of the request

  • data: *

    Request content

  • config: object

    optional configuration object - see UB.xhr

# query (ubqobject, allowBufferoptboolean) → Promise instance

Promise of running UBQL command(s) (asynchronously). The difference from UBConnection.post is:

  • ability to buffer request: can merge several query in the 20ms period into one ubql call

For well known UnityBase methods use aliases (addNew, select, insert, update, doDelete)

Arguments:
  • ubq: object

    Request to execute

  • allowBuffer: boolean

    Allow buffer this request to single runList. False by default

  
      //this two execution is passed to single ubql server execution
$App.connection.query({entity: 'uba_user', method: 'select', fieldList: ['*']}, true).then(UB.logDebug);
$App.connection.query({entity: 'ubm_navshortcut', method: 'select', fieldList: ['*']}, true).then(UB.logDebug);

//but this request is passed in separate ubql (because allowBuffer false in first request
$App.connection.query({entity: 'uba_user', method: 'select', fieldList: ['*']}).then(UB.logDebug);
$App.connection.query({entity: 'ubm_desktop', method: 'select', fieldList: ['*']}, true).then(UB.logDebug);
  

# queryAsObject (ubqobject, fieldAliasesoptObject.<string, string>, allowBufferoptboolean) → Promise.<(Array | null)> instance

Promise of running UBQL command(s) (asynchronously).

Result is array of objects or null.

The difference from UBConnection.post is:

  • ability to buffer request: can merge several query in the 20ms period into one ubql call

For well known UnityBase methods use aliases (addNew, select, insert, update, doDelete)

Arguments:
  • ubq: object

    Request to execute

  • fieldAliases: Object.<string, string>

    Optional object to change attribute names during transform array to object. Keys are original names, values - new names

  • allowBuffer: boolean

    Allow buffer this request to single runList. False by default

  
      //this two execution is passed to single ubql server execution
$App.connection.queryAsObject({entity: 'uba_user', method: 'select', fieldList: ['*']}, true).then(UB.logDebug);
$App.connection.queryAsObject({entity: 'ubm_navshortcut', method: 'select', fieldList: ['*']}, true).then(UB.logDebug);

//but this request is passed in separate ubql (because allowBuffer false in first request
$App.connection.queryAsObject({entity: 'uba_user', method: 'select', fieldList: ['*']}).then(UB.logDebug);
$App.connection.queryAsObject({entity: 'ubm_desktop', method: 'select', fieldList: ['*']}, true).then(UB.logDebug);
  

# Repository (entityCodeOrUBQLString) → ClientRepository instance

Create a new instance of repository

Arguments:
  • entityCodeOrUBQL: String| Object

    The name of the Entity for which the Repository is being created or UBQL

# runTrans (ubRequestArrayArray.<ubRequest>) → Promise instance

Group several ubRequest into one server request (executed in singe transaction on server side)

 $App.connection.runTrans([
      { entity: 'my_entity', method: 'update', ID: 1, execParams: {code: 'newCode'} },
      { entity: 'my_entity', method: 'update', ID: 2, execParams: {code: 'newCodeforElementWithID=2'} },
  ]).then(UB.logDebug);

Return:

Resolved to response.data

Arguments:

# runTransAsObject (ubRequestArrayArray.<ubRequest>, fieldAliasesArrayoptArray.<Object.<string, string>>) → Promise.<Array.<object>> instance

Group several ubRequest into one server request (executed in singe transaction on server side)

Each response will be returned in the same array position as corresponding request.

In case response contains resultData property of type {data: fields: } it will be converted to array-of-object dataStore format

In case method is insert or update array is replaced by first element. Example below use one entity, but real app can use any combination of entities and methods

Arguments:
  • ubRequestArray: Array.<ubRequest>
  • fieldAliasesArray: Array.<Object.<string, string>>

    Optional array of object to change attribute names during transform. Keys are original names, values - new names

  
      $App.connection.runTransAsObject([
  {entity: "tst_aclrls", method: 'insert', fieldList: ['ID', 'caption'], execParams: {caption: 'inserted1'}},
  {entity: "tst_aclrls", method: 'insert', opaqueParam: 'insertWoFieldList', execParams: {caption: 'inserted2'}},
  {entity: "tst_aclrls", method: 'update', fieldList: ['ID', 'caption'], execParams: {ID: 332463213805569, caption: 'updated1'}},
  {entity: "tst_aclrls", method: 'delete', execParams: {ID: 332463213805572}}]
).then(UB.logDebug)
// result is:
 [{
   "entity": "tst_aclrls","method": "insert","fieldList": ["ID","caption"],"execParams": {"caption": "inserted1","ID": 332463256010753},
   "resultData": {"ID": 332463256010753,"caption": "inserted1"}
 }, {
   "entity": "tst_aclrls","method": "insert","opaqueParam": "insertWoFieldList","execParams": {"caption": "inserted2","ID": 332463256010756},"fieldList": []
 }, {
   "entity": "tst_aclrls","method": "update","fieldList": ["ID","caption"],"execParams": {"ID": 332463213805569,"caption": "updated1"},
   "resultData": {"ID": 332463213805569,"caption": "updated1"}
 }, {
   "entity": "tst_aclrls","method": "delete","execParams": {"ID": 332463213805572},
   "ID": 332463213805572
 }]
  

# select (serverRequestobject, bypassCacheoptboolean) → Promise instance

Promise of running UBQL (asynchronously). Two difference from UBConnection.query:

  • ubRequest.method by default set to 'select'
  • requests is always buffered in the 20ms period into one ubql call
  • Date & 'DateTime' entity attributes are converted from ISO8601 text representation to javaScript Date object
  • if request entity is cached - cache used

Arguments:
  • serverRequest: object
    • entitystring

      Entity to execute the method

    • methodstring

      Method of entity to executed. Default to 'select'

    • IDnumber

      if passed - request bypass cache, where & order list is ignored. Can be used to load single record from server

    • fieldListArray.<string>

    • whereListobject

    • execParamsobject

    • optionsobject

    • lockTypestring

    • alsNeedboolean

    • __skipOptimisticLockboolean

      In case this parameter true and in the buffered

    Request to execute

  • bypassCache = false: boolean

    Do not use cache while request even if entity cached. If __mip_disablecache: true is passed in serverRequest cache is also disabled.

  
      //retrieve users
 $App.connection.select({entity: 'uba_user', fieldList: ['*']}).then(UB.logDebug);

 //retrieve users and desktops and then both done - do something
 Promise.all($App.connection.select({entity: 'uba_user', fieldList: ['ID', 'name']})
   $App.connection.select({entity: 'ubm_desktop', fieldList: ['ID', 'code']})
 ).then(UB.logDebug);
  

# serverErrorByCode (errorNumnumber) → string instance

Return server-side error message by error number

Arguments:

# setDocument (content*, paramsobject, onProgressoptfunction) → Promise.<object> instance

Saves a file content to the TEMP store of the specified entity attribute of Document type.

Should be called before insert of update. Result of this function is what shall be assigned to the attribute value during insert/update operation.

Return:

Promise resolved blob store metadata

Arguments:
  • content: *

    BLOB attribute content

  • params: object
    • entitystring

      Entity name

    • attributestring

      Entity attribute name

    • idnumber

      ID of the record

    • origNamestring

    • chunkSizeMbnumber

      Chunks size in Mb. Can be set for each request individually.

      • If not defined - uiSettings.adminUI.uploadChunkSizeMb is used
      • if === 0 - chunked upload will be disabled

    • fileNamestring

      If not specified, params.origName will be used

    • encodingstring

      Encoding of data. Either omit for binary data or set to base64 for base64 encoded data

    Additional parameters

  • onProgress: function

    Optional onProgress callback

# setPreferredUData (preferredUDataobject) instance

Sets currently logged-in user preferred uData (stored in localStorage for specified user). Preferred uData passed as prefUData URL param during /auth handshake and can be used in server-side Session.on('login') handler

Arguments:
  • preferredUData: object| null

    If null - preferred user data will be deleted

# setRequest2faFunction (onRequest2farequest2faCallback) instance

Allow to override a connection onRequest2fa function passed as config to UBConnection instance

Arguments:
  • onRequest2fa: request2faCallback

    Function with the same signature as requestAuthParams parameter in UBConnection constructor

# setRequestAuthParamsFunction (authParamsFuncauthParamsCallback) instance

Allow to override a connection requestAuthParams function passed as config to UBConnection instance

Arguments:
  • authParamsFunc: authParamsCallback

    Function with the same signature as requestAuthParams parameter in UBConnection constructor

# setUiTag (uiTagstring) instance

Sets UI tag for connection.

This tag will be added to a ubql HTTP request as uitag=${uiTag} and can be used to track from which part of UI request is generated

Recommended naming convention for tags are:

  • nsc-${shortcutCode} for something executed from navshortcut
  • frm-${formCode} for forms
  • afm-${entity} for auto-forms
  • rpt-${reportCode} for reports

Arguments:

# switchCurrentSession (sessionUBSession) instance

Switch current session. Use only on server side

Arguments:

# update (serverRequestobject, allowBufferoptboolean) → Promise.<object> instance

Promise of running UBQL command with update method (asynchronously). Difference from UBConnection.query:

  • ubRequest.method set to 'update'
  • Date & 'DateTime' entity attributes are converted from ISO8601 text representation to javaScript Date object
  • if necessary it will clear cache

In case fieldList is passed - result will contains updated values for attributes specified in fieldList in Array representation

Arguments:
  • serverRequest: object

    Request to execute

  • allowBuffer = false: boolean

    Allow several "in the same time" request to be buffered to one transaction.

  
      $App.connection.update({
   entity: 'uba_user',
   fieldList: ['ID','name', 'mi_modifyDate'],
   execParams: {ID: 332462122205200, name:'test', mi_modifyDate:"2019-04-23T13:00:00Z"}
 }).then(UB.logDebug);
 // [{"entity":"uba_user","fieldList":["ID","name","mi_modifyDate"],
 //   "execParams":{"ID":332462122205200,"name":"test","mi_modifyDate":"2019-04-23T13:03:51Z","mi_modifyUser":10},
 //   "method":"update",
 //   "resultData":{"fields":["ID","name","mi_modifyDate"],"rowCount": 1,
 //               "data":[[332462122205200,"test","2019-04-23T13:03:51Z"]]}
 // }]
  

# updateAsObject (serverRequestobject, fieldAliasesoptObject.<string, string>, allowBufferoptboolean) → Promise.<object> instance

Promise of running UBQL command with update method (asynchronously).

In case fieldList is passed - result will contain updated values for attributes specified in fieldList as Object;

If fieldList is not passed or empty - return null

Arguments:
  • serverRequest: object

    Request to execute

  • fieldAliases: Object.<string, string>

    Optional object to change attribute names during transform array to object. Keys are original names, values - new names

  • allowBuffer = false: boolean

    Allow several "in the same time" request to be buffered to one transaction.

  
      $App.connection.updateAsObject({
  entity: 'uba_user',
  fieldList: ['ID','name','mi_modifyDate', 'isPending'],
  execParams: {ID: 33246, name:'newName', mi_modifyDate:"2019-04-23T13:00:00Z"}
}).then(UB.logDebug);
// {"ID": 332462122205200, "name": newName", "mi_modifyDate": new Date("2019-04-23T13:03:51Z"), isPending: false}
  

# userCanChangePassword () → boolean instance

Is auth schema for logged-in user allows password changing (currently - only UB and CERT* with requireUserName)

# userData (keyoptstring) → * instance

Return custom data for logged-in user, or {lang: 'en', login: 'anonymous'} in case not logged in

If key is provided - return only key part of user data. For a list of possible keys see Session.uData in server side documentation

Arguments:
  
      $App.connection.userData('lang');
// or the same but dedicated alias
$App.connection.userLang()
  

# userLang () → string instance

Return current user language or 'en' in case not logged in

# userLogin () → string instance

Return current user logon name or 'anonymous' in case not logged in

# xhr (configobject) → Promise.<XHRResponse> instance

Shortcut method to perform authorized/encrypted request to application we connected. Will:

By default, xhr retrieve data in JSON format, but for ubql endpoint can accept Content-Type header and serialize DataStore in one of:

  • text/xml; charset=UTF-8
  • application/vnd.oasis.opendocument.spreadsheet
  • text/csv; charset=UTF-8
  • text/html; charset=UTF-8

Arguments:
  
      // get response as CSV and save it to file
 const { data } = await UB.connection.xhr({
   method: 'POST',
   url: 'ubql',
   data: [UB.Repository.attrs('*').ubql()],
   responseType: 'blob',
   headers: { 'Content-Type': 'text/csv; charset=UTF-8' }
 })
 window.saveAs(data, `${fileName}.csv`)
  

Events

# authorizationFail  --> (reason*, connUBConnection)

Fired for UBConnection instance in case of bad authorization

Arguments:

# authorized  --> (connUBConnection, sessionUBSession, authParamsoptobject)

Fired for UBConnection instance after success authorization

Arguments:

# defineLoginName  --> (connUBConnection, urlParamsobject, certInfoobject)

Fired for UBConnection instance in case authentication type CERT and simpleCertAuth is true just after private key is loaded and certificate is parsed but before auth handshake starts.

Here you can extract username from certificate. By default, it is EDPOU or DRFO or email.

Arguments:

# entity_name:changed  --> (ubqlResponseobject)

Fires after successful response for update/insert/delete for entity received

  
      UB.connection.on('uba_user:changed', function ({entity, method, resultData}) {
  console.log(`Someone call ${method} User with ID ${resultData.ID}`
})
  
Arguments:

# entity_name:refresh  --> (payloadobject)

Fires just after form is refreshed using processing.refresh()

  
      // @param {THTTPRequest} req
UB.connection.on('uba_user:refresh', function (data) {
  console.log(`Someone call refresh for User with ID ${data.ID}`
})
  
Arguments:
  • payload: object
    • IDnumber

      and ID of entity_name instance what refreshed

# passwordExpired  --> ()

Fired for UBConnection instance in case user password is expired. The only valid endpoint after this is changePassword

Accept 1 arg `(connection: UBConnection)