Skip to content

Commit 997eeb7

Browse files
committed
- add Backendless.apiKey and Backendless.appId getters
1 parent 7d79169 commit 997eeb7

File tree

7 files changed

+127
-46
lines changed

7 files changed

+127
-46
lines changed

backendless.d.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
declare module Backendless {
66
let debugMode: boolean;
77
let serverURL: string;
8-
let applicationId: string;
9-
let secretKey: string;
8+
let appId: string;
9+
let apiKey: string;
1010
let appPath: string;
1111
let domain: string;
1212
let apiURI: string;
@@ -17,6 +17,12 @@ declare module Backendless {
1717
version: string;
1818
};
1919

20+
/** @deprecated **/
21+
let applicationId: string;
22+
23+
/** @deprecated **/
24+
let secretKey: string;
25+
2026
/**
2127
* @dictionary
2228
*/

src/index.js

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ class Backendless {
9797
* @param {Object} config
9898
*/
9999
initConfig(config) {
100+
config = { ...config }
101+
102+
if (config.domain) {
103+
delete config.appId
104+
delete config.apiKey
105+
}
106+
100107
for (const key in DEFAULT_PROPS) {
101108
if (DEFAULT_PROPS.hasOwnProperty(key)) {
102109
const privateKey = `__${key}`
@@ -118,7 +125,7 @@ class Backendless {
118125

119126
/**
120127
* @param {string|Object} appId|domain|config
121-
* @param {string} [secretKey]
128+
* @param {string} [apiKey]
122129
* @returns {Backendless}
123130
*/
124131
initApp() {
@@ -183,26 +190,24 @@ class Backendless {
183190
)
184191
}
185192

186-
///--------applicationId-------///
187-
get applicationId() {
193+
get appId() {
188194
return this.__appId
189195
}
190196

191-
set applicationId(appId) {
197+
set appId(appId) {
192198
throw new Error(
193-
`Setting '${appId}' value to Backendless.applicationId directly is not possible, ` +
199+
`Setting '${appId}' value to Backendless.appId directly is not possible, ` +
194200
`instead you must use Backendless.initApp('${appId}', API_KEY)`
195201
)
196202
}
197203

198-
///--------secretKey-------///
199-
get secretKey() {
204+
get apiKey() {
200205
return this.__apiKey
201206
}
202207

203-
set secretKey(apiKey) {
208+
set apiKey(apiKey) {
204209
throw new Error(
205-
`Setting '${apiKey}' value to Backendless.secretKey directly is not possible, ` +
210+
`Setting '${apiKey}' value to Backendless.apiKey directly is not possible, ` +
206211
`instead you must use Backendless.initApp(APP_ID, '${apiKey}')`
207212
)
208213
}
@@ -240,7 +245,7 @@ class Backendless {
240245
return this.domain + this.apiURI
241246
}
242247

243-
return [this.serverURL, this.applicationId, this.secretKey].join('/')
248+
return [this.serverURL, this.appId, this.apiKey].join('/')
244249
}
245250

246251
set appPath(appPath) {
@@ -412,7 +417,37 @@ class Backendless {
412417
///-------------------------------------///
413418
///--------BACKWARD COMPATIBILITY-------///
414419

415-
//TODO: do we need to remove it?
420+
/** @deprecated */
421+
get applicationId() {
422+
// eslint-disable-next-line no-console
423+
console.warn('getter/setter for Backendless.applicationId is deprecated, instead use Backendless.appId')
424+
425+
return this.appId
426+
}
427+
428+
/** @deprecated */
429+
set applicationId(appId) {
430+
// eslint-disable-next-line no-console
431+
console.warn('getter/setter for Backendless.applicationId is deprecated, instead use Backendless.appId')
432+
433+
this.appId = appId
434+
}
435+
436+
/** @deprecated */
437+
get secretKey() {
438+
// eslint-disable-next-line no-console
439+
console.warn('getter/setter for Backendless.secretKey is deprecated, instead use Backendless.apiKey')
440+
441+
return this.apiKey
442+
}
443+
444+
/** @deprecated */
445+
set secretKey(apiKey) {
446+
// eslint-disable-next-line no-console
447+
console.warn('getter/setter for Backendless.secretKey is deprecated, instead use Backendless.apiKey')
448+
449+
this.apiKey = apiKey
450+
}
416451

417452
/** @deprecated */
418453
get Persistence() {

src/rt.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function loadAppInfo(appPath) {
1212

1313
export default class RT extends BackendlessRTClient {
1414
constructor(app) {
15-
const { applicationId: appId, secretKey: apiKey, appPath, debugMode } = app
15+
const { appId, apiKey, appPath, debugMode } = app
1616

1717
const clientId = Utils.uuid()
1818
const lookupPath = `${appPath}/rt/lookup`

test/e2e/specs/init-app.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,28 @@ describe('initApp', function() {
1212
it('should change public app relevant variables in Backendless scope', function() {
1313
Backendless.initApp(APP_ID, API_KEY)
1414

15-
expect(Backendless.applicationId).to.be.equal(APP_ID)
16-
expect(Backendless.secretKey).to.be.equal(API_KEY)
15+
expect(Backendless.appId).to.be.equal(APP_ID)
16+
expect(Backendless.apiKey).to.be.equal(API_KEY)
1717
})
1818

1919
it('should change public app relevant variables in Backendless scope using object config', function() {
2020
Backendless.initApp({ appId: APP_ID, apiKey: API_KEY })
2121

22-
expect(Backendless.applicationId).to.be.equal(APP_ID)
23-
expect(Backendless.secretKey).to.be.equal(API_KEY)
22+
expect(Backendless.appId).to.be.equal(APP_ID)
23+
expect(Backendless.apiKey).to.be.equal(API_KEY)
2424
})
2525

2626
it('should not public variables in Backendless scope', function() {
2727
Backendless.initApp(APP_ID, API_KEY)
2828

2929
const appPath = Backendless.appPath
3030

31-
expect(() => Backendless.applicationId = 'applicationId').to.throw() // eslint-disable-line
32-
expect(() => Backendless.secretKey = 'secretKey').to.throw() // eslint-disable-line
31+
expect(() => Backendless.appId = 'appId').to.throw() // eslint-disable-line
32+
expect(() => Backendless.apiKey = 'apiKey').to.throw() // eslint-disable-line
3333
expect(() => Backendless.appPath = 'appPath').to.throw() // eslint-disable-line
3434

35-
expect(Backendless.applicationId).to.be.equal(APP_ID)
36-
expect(Backendless.secretKey).to.be.equal(API_KEY)
35+
expect(Backendless.appId).to.be.equal(APP_ID)
36+
expect(Backendless.apiKey).to.be.equal(API_KEY)
3737
expect(Backendless.appPath).to.be.equal(appPath)
3838
})
3939

@@ -43,11 +43,11 @@ describe('initApp', function() {
4343
const app2 = Backendless.initApp({ appId: 'appId-2', apiKey: 'apiKey-2', standalone: true })
4444
const app3 = Backendless.initApp({ appId: 'appId-3', apiKey: 'apiKey-3', standalone: true })
4545

46-
expect(app2.applicationId).to.be.equal('appId-2')
47-
expect(app2.secretKey).to.be.equal('apiKey-2')
46+
expect(app2.appId).to.be.equal('appId-2')
47+
expect(app2.apiKey).to.be.equal('apiKey-2')
4848

49-
expect(app3.applicationId).to.be.equal('appId-3')
50-
expect(app3.secretKey).to.be.equal('apiKey-3')
49+
expect(app3.appId).to.be.equal('appId-3')
50+
expect(app3.apiKey).to.be.equal('apiKey-3')
5151
})
5252
})
5353
})

test/e2e/specs/users.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe('Backendless.Users', function() {
5050

5151
const result = require('../../../lib').noConflict()
5252
result.serverURL = Backendless.serverURL
53-
result.initApp(Backendless.applicationId, Backendless.secretKey)
53+
result.initApp(Backendless.appId, Backendless.apiKey)
5454

5555
return result
5656
}

test/tsd.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import Counter = Backendless.Counter;
44

55
function testMain() {
6+
const appId: string = Backendless.appId;
7+
const apiKey: string = Backendless.apiKey;
68
const applicationId: string = Backendless.applicationId;
79
const secretKey: string = Backendless.secretKey;
810
const serverURL: string = Backendless.serverURL;

test/unit/specs/namespace.js

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,29 @@ describe('Namespace', function() {
1818
it('should change public app relevant variables in Backendless scope', () => {
1919
Backendless.initApp(APP_ID, API_KEY)
2020

21-
expect(Backendless.applicationId).to.be.equal(APP_ID)
22-
expect(Backendless.secretKey).to.be.equal(API_KEY)
21+
expect(Backendless.appId).to.be.equal(APP_ID)
22+
expect(Backendless.apiKey).to.be.equal(API_KEY)
2323
})
2424

2525
it('should change public app relevant variables in Backendless scope using object config', () => {
2626
Backendless.initApp({ appId: APP_ID, apiKey: API_KEY })
2727

28-
expect(Backendless.applicationId).to.be.equal(APP_ID)
29-
expect(Backendless.secretKey).to.be.equal(API_KEY)
28+
expect(Backendless.appId).to.be.equal(APP_ID)
29+
expect(Backendless.apiKey).to.be.equal(API_KEY)
3030
})
3131

3232
it('should not change public variables in Backendless scope', () => {
3333
Backendless.serverURL = 'http://foo.bar'
3434
Backendless.initApp(APP_ID, API_KEY)
3535

36-
expect(() => Backendless.applicationId = 'applicationId').to.throw()
37-
expect(() => Backendless.secretKey = 'secretKey').to.throw()
36+
expect(() => Backendless.appId = 'appId').to.throw()
37+
expect(() => Backendless.apiKey = 'apiKey').to.throw()
3838
expect(() => Backendless.appPath = 'appPath').to.throw()
3939
expect(() => Backendless.standalone = 'standalone').to.throw()
4040
expect(() => Backendless.device = 'device').to.throw()
4141

42-
expect(Backendless.applicationId).to.be.equal(APP_ID)
43-
expect(Backendless.secretKey).to.be.equal(API_KEY)
42+
expect(Backendless.appId).to.be.equal(APP_ID)
43+
expect(Backendless.apiKey).to.be.equal(API_KEY)
4444
expect(Backendless.appPath).to.be.equal(`http://foo.bar/${APP_ID}/${API_KEY}`)
4545
})
4646
})
@@ -51,11 +51,11 @@ describe('Namespace', function() {
5151
const app2 = Backendless.initApp({ appId: 'appId-2', apiKey: 'apiKey-2', standalone: true })
5252
const app3 = Backendless.initApp({ appId: 'appId-3', apiKey: 'apiKey-3', standalone: true })
5353

54-
expect(app2.applicationId).to.be.equal('appId-2')
55-
expect(app2.secretKey).to.be.equal('apiKey-2')
54+
expect(app2.appId).to.be.equal('appId-2')
55+
expect(app2.apiKey).to.be.equal('apiKey-2')
5656

57-
expect(app3.applicationId).to.be.equal('appId-3')
58-
expect(app3.secretKey).to.be.equal('apiKey-3')
57+
expect(app3.appId).to.be.equal('appId-3')
58+
expect(app3.apiKey).to.be.equal('apiKey-3')
5959
})
6060

6161
it('has custom serverURL', () => {
@@ -66,8 +66,8 @@ describe('Namespace', function() {
6666
standalone: true
6767
})
6868

69-
expect(app1.applicationId).to.be.equal('appId-1')
70-
expect(app1.secretKey).to.be.equal('apiKey-1')
69+
expect(app1.appId).to.be.equal('appId-1')
70+
expect(app1.apiKey).to.be.equal('apiKey-1')
7171
expect(app1.appPath).to.be.equal('http://my-server-url.com/appId-1/apiKey-1')
7272
})
7373
})
@@ -77,18 +77,18 @@ describe('Namespace', function() {
7777
it('should init with custom domain', () => {
7878
Backendless.initApp(CUSTOM_DOMAIN)
7979

80-
expect(Backendless.applicationId).to.be.equal(null)
81-
expect(Backendless.secretKey).to.be.equal(null)
80+
expect(Backendless.appId).to.be.equal(null)
81+
expect(Backendless.apiKey).to.be.equal(null)
8282
expect(Backendless.domain).to.be.equal(CUSTOM_DOMAIN)
8383
expect(Backendless.appPath).to.be.equal(`${CUSTOM_DOMAIN}/api`)
8484
expect(Backendless.apiURI).to.be.equal('/api')
8585
})
8686

8787
it('should init with custom domain via config object', () => {
88-
Backendless.initApp({ domain: CUSTOM_DOMAIN, secretKey: 'XXX' })
88+
Backendless.initApp({ domain: CUSTOM_DOMAIN, apiKey: 'XXX' })
8989

90-
expect(Backendless.applicationId).to.be.equal(null)
91-
expect(Backendless.secretKey).to.be.equal(null)
90+
expect(Backendless.appId).to.be.equal(null)
91+
expect(Backendless.apiKey).to.be.equal(null)
9292
expect(Backendless.domain).to.be.equal(CUSTOM_DOMAIN)
9393
expect(Backendless.appPath).to.be.equal(`${CUSTOM_DOMAIN}/api`)
9494
expect(Backendless.apiURI).to.be.equal('/api')
@@ -101,6 +101,8 @@ describe('Namespace', function() {
101101
expect(Backendless.domain).to.be.equal(CUSTOM_DOMAIN)
102102
expect(Backendless.appPath).to.be.equal(`${CUSTOM_DOMAIN}/my-api-uri`)
103103
expect(Backendless.apiURI).to.be.equal('/my-api-uri')
104+
105+
Backendless.apiURI = undefined
104106
})
105107

106108
it('should fails with custom domain which does not start on https or http', () => {
@@ -351,5 +353,41 @@ describe('Namespace', function() {
351353
expect(global.Backendless).to.equal(undefined)
352354
})
353355

356+
it('should support deprecated applicationId and secretKey', function() {
357+
Backendless.initApp(APP_ID, API_KEY)
358+
359+
// eslint-disable-next-line no-console
360+
const _nativeConsoleWarn = console.warn
361+
362+
// eslint-disable-next-line no-console
363+
const spyConsoleWarn = console.warn = chai.spy()
364+
365+
expect(Backendless.applicationId).to.be.equal(APP_ID)
366+
expect(Backendless.secretKey).to.be.equal(API_KEY)
367+
expect(() => Backendless.applicationId = 'applicationId').to.throw('') // eslint-disable-line
368+
expect(() => Backendless.secretKey = 'secretKey').to.throw('') // eslint-disable-line
369+
370+
Backendless.initApp({ domain: 'https://foo.com', apiKey: 'XXX' })
371+
372+
expect(Backendless.appId).to.be.equal(null)
373+
expect(Backendless.apiKey).to.be.equal(null)
374+
expect(Backendless.domain).to.be.equal('https://foo.com')
375+
expect(Backendless.appPath).to.be.equal('https://foo.com/api')
376+
expect(Backendless.apiURI).to.be.equal('/api')
377+
378+
const appIdWarnMsg = 'getter/setter for Backendless.applicationId is deprecated, instead use Backendless.appId'
379+
const apiKeyWarnMsg = 'getter/setter for Backendless.secretKey is deprecated, instead use Backendless.apiKey'
380+
381+
expect(spyConsoleWarn).to.have.been.called.exactly(4)
382+
383+
expect(spyConsoleWarn).on.nth(1).be.called.with(appIdWarnMsg)
384+
expect(spyConsoleWarn).on.nth(2).be.called.with(apiKeyWarnMsg)
385+
expect(spyConsoleWarn).on.nth(3).be.called.with(appIdWarnMsg)
386+
expect(spyConsoleWarn).on.nth(4).be.called.with(apiKeyWarnMsg)
387+
388+
// eslint-disable-next-line no-console
389+
console.warn = _nativeConsoleWarn
390+
})
391+
354392
})
355393
})

0 commit comments

Comments
 (0)