Skip to content
Merged

5.1 #120

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@
},
"dependencies": {
"backendless-request": "~0.0.11",
"backendless-rt-client": "0.0.15"
"backendless-rt-client": "0.0.16"
}
}
195 changes: 142 additions & 53 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,7 @@
import Request from 'backendless-request'

import Logging from './logging'
import Counters from './counters'
import Cache from './cache'
import Commerce from './commerce'
import Users from './users'
import User from './users/user'
import CustomServices from './bl/custom-services'
import Events from './bl/events'
import Geo from './geo'
import Data from './data'
import Messaging from './messaging'
import Device from './device'
import Files from './files'
import RT, { setRTDebugMode } from './rt'
import SharedObject from './rso'
import LocalCache from './local-cache'
import LocalVars from './local-vars'

import { initApp } from './init-app'
import { getUserAgent } from './user-agent'
import { getCurrentUserToken } from './users/current-user'

const root = (typeof self === 'object' && self.self === self && self) ||
(typeof global === 'object' && global.global === global && global)

Expand All @@ -36,7 +16,7 @@ const Backendless = {
set debugMode(debugMode) {
LocalVars.debugMode = !!debugMode

setRTDebugMode(LocalVars.debugMode)
require('./rt').setRTDebugMode(LocalVars.debugMode)
},

get serverURL() {
Expand All @@ -59,14 +39,35 @@ const Backendless = {
return LocalVars.applicationId
},

set applicationId(appId) {
throw new Error(
`Setting '${appId}' value to Backendless.applicationId directly is not possible, ` +
`instead you must use Backendless.initApp('${appId}', API_KEY)`
)
},

get secretKey() {
return LocalVars.secretKey
},

set secretKey(apiKey) {
throw new Error(
`Setting '${apiKey}' value to Backendless.secretKey directly is not possible, ` +
`instead you must use Backendless.initApp(APP_ID, '${apiKey}')`
)
},

get appPath() {
return LocalVars.appPath
},

set appPath(appPath) {
throw new Error(
`Setting '${appPath}' value to Backendless.appPath directly is not possible, ` +
'instead you must use Backendless.initApp(APP_ID, API_KEY) for setup the value'
)
},

get ServerCode() {
return LocalVars.ServerCode
},
Expand All @@ -75,13 +76,23 @@ const Backendless = {
LocalVars.ServerCode = ServerCode
},

initApp,
initApp(...args) {
require('./init-app').initApp(...args)
},

getCurrentUserToken() {
return require('./users/current-user').getCurrentUserToken()
},

getCurrentUserToken,
setupDevice(...args) {
const { default: Device } = require('./device')

setupDevice: Device.setup,
Device.setup(...args)
},

browser: getUserAgent(),
get browser() {
return require('./user-agent').getUserAgent()
},

Request,

Expand All @@ -96,20 +107,61 @@ const Backendless = {
///-------------------------------------///
///-------------- SERVICES -------------///

Logging : Logging,
Counters : Counters,
Cache : Cache,
Commerce : Commerce,
Users : Users,
User : User,
CustomServices: CustomServices,
Events : Events,
Geo : Geo,
Data : Data,
Messaging : Messaging,
Files : Files,
RT : RT,
SharedObject : SharedObject,
get Logging() {
return require('./logging').default
},

get Counters() {
return require('./counters').default
},

get Cache() {
return require('./cache').default
},

get Commerce() {
return require('./commerce').default
},

get Users() {
return require('./users').default
},

get User() {
return require('./users/user').default
},

get CustomServices() {
return require('./bl/custom-services').default
},

get Events() {
return require('./bl/events').default
},

get Geo() {
return require('./geo').default
},

get Data() {
return require('./data').default
},

get Messaging() {
return require('./messaging').default
},

get Files() {
return require('./files').default
},

get RT() {
return require('./rt').default
},

get SharedObject() {
return require('./rso').default
},

///-------------- SERVICES -------------///
///-------------------------------------///
Expand All @@ -118,22 +170,59 @@ const Backendless = {
///--------BACKWARD COMPATIBILITY-------///

//TODO: do we need to remove it?
UserService : Users,
GeoQuery : Geo.Query,
GeoPoint : Geo.Point,
GeoCluster : Geo.Cluster,
Persistence : Data,
DataQueryBuilder : Data.QueryBuilder,
LoadRelationsQueryBuilder: Data.LoadRelationsQueryBuilder,
Bodyparts : Messaging.Bodyparts,
PublishOptions : Messaging.PublishOptions,
DeliveryOptions : Messaging.DeliveryOptions,
PublishOptionsHeaders : Messaging.PublishOptionsHeaders,

LocalCache,

get UserService() {
return Backendless.Users
},

get GeoQuery() {
return Backendless.Geo.Query
},

get GeoPoint() {
return Backendless.Geo.Point
},

get GeoCluster() {
return Backendless.Geo.Cluster
},

get Persistence() {
return Backendless.Data
},

get DataQueryBuilder() {
return Backendless.Data.QueryBuilder
},

get LoadRelationsQueryBuilder() {
return Backendless.Data.LoadRelationsQueryBuilder
},

get Bodyparts() {
return Backendless.Messaging.Bodyparts
},

get PublishOptions() {
return Backendless.Messaging.PublishOptions
},

get DeliveryOptions() {
return Backendless.Messaging.DeliveryOptions
},

get PublishOptionsHeaders() {
return Backendless.Messaging.PublishOptionsHeaders
},

get LocalCache() {
return require('./local-cache').default
},

/** @deprecated */
SubscriptionOptions : Messaging.SubscriptionOptions,
get SubscriptionOptions() {
return Backendless.Messaging.SubscriptionOptions
},

///--------BACKWARD COMPATIBILITY-------///
///-------------------------------------///
Expand Down
14 changes: 7 additions & 7 deletions src/init-app.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import LocalVars from './local-vars'
import LoggingCollector from './logging/collector'
import GeoTrackerMonitor from './geo/tracker-monitor'
import { initRTClient } from './rt'
import { setLocalCurrentUser } from './users/current-user'

export function initApp(appId, secretKey) {
const { default: LocalVars } = require('./local-vars')
const { default: LoggingCollector } = require('./logging/collector')
const { default: GeoTracker } = require('./geo/tracker-monitor/tracker')
const { initRTClient } = require('./rt')
const { setLocalCurrentUser } = require('./users/current-user')

LocalVars.applicationId = appId
LocalVars.secretKey = secretKey
LocalVars.appPath = [LocalVars.serverURL, appId, secretKey].join('/')

initRTClient()

LoggingCollector.reset()
GeoTrackerMonitor.reset()
GeoTracker.reset()

setLocalCurrentUser()
}
10 changes: 6 additions & 4 deletions src/logging/collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import Urls from '../urls'
import Request from '../request'
import Async from '../request/async'

import Logger from './logger'

let lastFlushListeners

function flush(asyncHandler) {
Expand Down Expand Up @@ -58,6 +56,8 @@ const LoggingCollector = {
},

getLogger(loggerName) {
const { default: Logger } = require('./logger')

if (!Utils.isString(loggerName)) {
throw new Error("Invalid 'loggerName' value. LoggerName must be a string value")
}
Expand All @@ -71,7 +71,7 @@ const LoggingCollector = {
message,
exception,
'log-level': logLevel,
timestamp: Date.now()
timestamp : Date.now()
}

LoggingCollector.pool.push(messageObj)
Expand All @@ -89,7 +89,9 @@ const LoggingCollector = {
flushSync: Utils.synchronized(flush),

sendRequest() {
LoggingCollector.flushInterval = setTimeout(() => LoggingCollector.flush(), LoggingCollector.timeFrequency * 1000)
if (!LoggingCollector.flushInterval) {
LoggingCollector.flushInterval = setTimeout(() => LoggingCollector.flush(), LoggingCollector.timeFrequency * 1000)
}
},

setLogReportingPolicy(numOfMessages, timeFrequency) {
Expand Down
4 changes: 2 additions & 2 deletions src/user-agent.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Utils from './utils'

export function getUserAgent() {
const { default: Utils } = require('./utils')

let ua = 'NodeJS'

if (Utils.isBrowser) {
Expand Down
7 changes: 4 additions & 3 deletions src/users/current-user.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import Utils from '../utils'
import User from './user'
import Data from '../data'
import Urls from '../urls'
import Request from '../request'
import Async from '../request/async'
Expand Down Expand Up @@ -40,14 +38,17 @@ export const getCurrentUser = asyncHandler => {
const currentUserId = stayLoggedIn && LocalCache.get('current-user-id')

if (currentUserId) {
const { default: Data } = require('../data')
const { default: User } = require('./user')

return Data.of(User).findById(currentUserId, asyncHandler)
}

return asyncHandler ? asyncHandler.success(null) : null
}

export function isValidLogin(/** async */) {
const userToken = LocalCache.get('user-token')
const userToken = getCurrentUserToken()
const responder = Utils.extractResponder(arguments)
const isAsync = !!responder

Expand Down
6 changes: 3 additions & 3 deletions test/e2e/specs/init-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ describe('initApp', function() {

const appPath = Backendless.appPath

expect(() => Backendless.applicationId = 'applicationId').to.throwError // eslint-disable-line
expect(() => Backendless.secretKey = 'secretKey').to.throwError // eslint-disable-line
expect(() => Backendless.appPath = 'appPath').to.throwError // eslint-disable-lin
expect(() => Backendless.applicationId = 'applicationId').to.throw() // eslint-disable-line
expect(() => Backendless.secretKey = 'secretKey').to.throw() // eslint-disable-line
expect(() => Backendless.appPath = 'appPath').to.throw() // eslint-disable-line

expect(Backendless.applicationId).to.be.equal(APP_ID)
expect(Backendless.secretKey).to.be.equal(SECRET_KEY)
Expand Down
Loading