Skip to content

Commit 1823535

Browse files
authored
Merge pull request #2259 from ParsePlatform/client-sdk-info
Exposes the ClientSDK infos if available
2 parents 3c1da3c + 2498a95 commit 1823535

12 files changed

+74
-30
lines changed

spec/InstallationsRouter.spec.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ describe('InstallationsRouter', () => {
2323
deviceType: 'android'
2424
}
2525
},
26-
query: {}
26+
query: {},
27+
info: {}
2728
};
2829

2930
var router = new InstallationsRouter();
@@ -56,7 +57,8 @@ describe('InstallationsRouter', () => {
5657
where: {
5758
deviceType: 'android'
5859
}
59-
}
60+
},
61+
info: {}
6062
};
6163

6264
var router = new InstallationsRouter();
@@ -87,7 +89,8 @@ describe('InstallationsRouter', () => {
8789
body: {},
8890
query: {
8991
limit: 0
90-
}
92+
},
93+
info: {}
9194
};
9295

9396
var router = new InstallationsRouter();
@@ -118,7 +121,8 @@ describe('InstallationsRouter', () => {
118121
body: {},
119122
query: {
120123
count: 1
121-
}
124+
},
125+
info: {}
122126
};
123127

124128
var router = new InstallationsRouter();
@@ -153,7 +157,8 @@ describe('InstallationsRouter', () => {
153157
query: {
154158
limit: 0,
155159
count: 1
156-
}
160+
},
161+
info: {}
157162
};
158163

159164
var router = new InstallationsRouter();

spec/Middlewares.spec.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,24 @@ describe('middlewares', () => {
6666
});
6767
});
6868
});
69+
70+
it('should properly parse the SDK versions', () => {
71+
let clientSDKFromVersion = middlewares.clientSDKFromVersion;
72+
expect(clientSDKFromVersion('i1.1.1')).toEqual({
73+
sdk: 'i',
74+
version: '1.1.1'
75+
});
76+
expect(clientSDKFromVersion('i1')).toEqual({
77+
sdk: 'i',
78+
version: '1'
79+
});
80+
expect(clientSDKFromVersion('apple-tv1.13.0')).toEqual({
81+
sdk: 'apple-tv',
82+
version: '1.13.0'
83+
});
84+
expect(clientSDKFromVersion('js1.9.0')).toEqual({
85+
sdk: 'js',
86+
version: '1.9.0'
87+
});
88+
})
6989
});

src/RestQuery.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ import { default as FilesController } from './Controllers/FilesController';
1414
// include
1515
// keys
1616
// redirectClassNameForKey
17-
function RestQuery(config, auth, className, restWhere = {}, restOptions = {}) {
17+
function RestQuery(config, auth, className, restWhere = {}, restOptions = {}, clientSDK) {
1818

1919
this.config = config;
2020
this.auth = auth;
2121
this.className = className;
2222
this.restWhere = restWhere;
23+
this.clientSDK = clientSDK;
2324
this.response = null;
2425
this.findOptions = {};
2526
if (!this.auth.isMaster) {

src/RestWrite.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ import _ from 'lodash';
2323
// RestWrite will handle objectId, createdAt, and updatedAt for
2424
// everything. It also knows to use triggers and special modifications
2525
// for the _User class.
26-
function RestWrite(config, auth, className, query, data, originalData) {
26+
function RestWrite(config, auth, className, query, data, originalData, clientSDK) {
2727
this.config = config;
2828
this.auth = auth;
2929
this.className = className;
30+
this.clientSDK = clientSDK;
3031
this.storage = {};
3132
this.runOptions = {};
32-
3333
if (!query && data.objectId) {
3434
throw new Parse.Error(Parse.Error.INVALID_KEY_NAME, 'objectId is an invalid field name.');
3535
}

src/Routers/ClassesRouter.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class ClassesRouter extends PromiseRouter {
4646
if (typeof body.where === 'string') {
4747
body.where = JSON.parse(body.where);
4848
}
49-
return rest.find(req.config, req.auth, req.params.className, body.where, options)
49+
return rest.find(req.config, req.auth, req.params.className, body.where, options, req.info.clientSDK)
5050
.then((response) => {
5151
if (response && response.results) {
5252
for (let result of response.results) {
@@ -77,7 +77,7 @@ export class ClassesRouter extends PromiseRouter {
7777
options.include = String(body.include);
7878
}
7979

80-
return rest.get(req.config, req.auth, req.params.className, req.params.objectId, options)
80+
return rest.get(req.config, req.auth, req.params.className, req.params.objectId, options, req.info.clientSDK)
8181
.then((response) => {
8282
if (!response.results || response.results.length == 0) {
8383
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Object not found.');
@@ -99,15 +99,15 @@ export class ClassesRouter extends PromiseRouter {
9999
}
100100

101101
handleCreate(req) {
102-
return rest.create(req.config, req.auth, req.params.className, req.body);
102+
return rest.create(req.config, req.auth, req.params.className, req.body, req.info.clientSDK);
103103
}
104104

105105
handleUpdate(req) {
106-
return rest.update(req.config, req.auth, req.params.className, req.params.objectId, req.body);
106+
return rest.update(req.config, req.auth, req.params.className, req.params.objectId, req.body, req.info.clientSDK);
107107
}
108108

109109
handleDelete(req) {
110-
return rest.del(req.config, req.auth, req.params.className, req.params.objectId)
110+
return rest.del(req.config, req.auth, req.params.className, req.params.objectId, req.info.clientSDK)
111111
.then(() => {
112112
return {response: {}};
113113
});

src/Routers/IAPValidationRouter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function validateWithAppStore(url, receipt) {
4343
}
4444

4545
function getFileForProductIdentifier(productIdentifier, req) {
46-
return rest.find(req.config, req.auth, '_Product', { productIdentifier: productIdentifier }).then(function(result){
46+
return rest.find(req.config, req.auth, '_Product', { productIdentifier: productIdentifier }, undefined, req.info.clientSDK).then(function(result){
4747
const products = result.results;
4848
if (!products || products.length != 1) {
4949
// Error not found or too many

src/Routers/InstallationsRouter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class InstallationsRouter extends ClassesRouter {
2626
}
2727

2828
return rest.find(req.config, req.auth,
29-
'_Installation', body.where, options)
29+
'_Installation', body.where, options, req.info.clientSDK)
3030
.then((response) => {
3131
return {response: response};
3232
});

src/Routers/SessionsRouter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class SessionsRouter extends ClassesRouter {
3636
throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN,
3737
'Session token required.');
3838
}
39-
return rest.find(req.config, Auth.master(req.config), '_Session', { sessionToken: req.info.sessionToken })
39+
return rest.find(req.config, Auth.master(req.config), '_Session', { sessionToken: req.info.sessionToken }, undefined, req.info.clientSDK)
4040
.then((response) => {
4141
if (!response.results || response.results.length == 0) {
4242
throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN,

src/Routers/UsersRouter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class UsersRouter extends ClassesRouter {
4747
let sessionToken = req.info.sessionToken;
4848
return rest.find(req.config, Auth.master(req.config), '_Session',
4949
{ sessionToken },
50-
{ include: 'user' })
50+
{ include: 'user' }, req.info.clientSDK)
5151
.then((response) => {
5252
if (!response.results ||
5353
response.results.length == 0 ||
@@ -145,7 +145,7 @@ export class UsersRouter extends ClassesRouter {
145145
let success = {response: {}};
146146
if (req.info && req.info.sessionToken) {
147147
return rest.find(req.config, Auth.master(req.config), '_Session',
148-
{ sessionToken: req.info.sessionToken }
148+
{ sessionToken: req.info.sessionToken }, undefined, req.info.clientSDK
149149
).then((records) => {
150150
if (records.results && records.results.length) {
151151
return rest.del(req.config, Auth.master(req.config), '_Session',

src/batch.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ function handleBatch(router, req) {
5252
body: restRequest.body,
5353
params: match.params,
5454
config: req.config,
55-
auth: req.auth
55+
auth: req.auth,
56+
info: req.info
5657
};
5758

5859
promises.push(match.handler(request).then((response) => {

src/middlewares.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ var Parse = require('parse/node').Parse;
66
var auth = require('./Auth');
77
var Config = require('./Config');
88

9+
function clientSDKFromVersion(version) {
10+
let versionRE = /([-a-zA-Z]+)([0-9\.]+)/;
11+
let match = version.toLowerCase().match(versionRE);
12+
if (match && match.length === 3) {
13+
return {
14+
sdk: match[1],
15+
version: match[2]
16+
}
17+
}
18+
}
19+
920
// Checks that the request is authorized for this app and checks user
1021
// auth too.
1122
// The bodyparser should run before this middleware.
@@ -25,7 +36,8 @@ function handleParseHeaders(req, res, next) {
2536
clientKey: req.get('X-Parse-Client-Key'),
2637
javascriptKey: req.get('X-Parse-Javascript-Key'),
2738
dotNetKey: req.get('X-Parse-Windows-Key'),
28-
restAPIKey: req.get('X-Parse-REST-API-Key')
39+
restAPIKey: req.get('X-Parse-REST-API-Key'),
40+
clientVersion: req.get('X-Parse-Client-Version')
2941
};
3042

3143
var basicAuth = httpAuth(req);
@@ -93,6 +105,10 @@ function handleParseHeaders(req, res, next) {
93105
}
94106
}
95107

108+
if (info.clientVersion) {
109+
info.clientSDK = clientSDKFromVersion(info.clientVersion);
110+
}
111+
96112
if (fileViaJSON) {
97113
// We need to repopulate req.body with a buffer
98114
var base64 = req.body.base64;
@@ -283,5 +299,6 @@ module.exports = {
283299
handleParseErrors: handleParseErrors,
284300
handleParseHeaders: handleParseHeaders,
285301
enforceMasterKeyAccess: enforceMasterKeyAccess,
286-
promiseEnforceMasterKeyAccess
302+
promiseEnforceMasterKeyAccess,
303+
clientSDKFromVersion
287304
};

src/rest.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@ var RestWrite = require('./RestWrite');
1515
var triggers = require('./triggers');
1616

1717
// Returns a promise for an object with optional keys 'results' and 'count'.
18-
function find(config, auth, className, restWhere, restOptions) {
18+
function find(config, auth, className, restWhere, restOptions, clientSDK) {
1919
enforceRoleSecurity('find', className, auth);
20-
let query = new RestQuery(config, auth, className, restWhere, restOptions);
20+
let query = new RestQuery(config, auth, className, restWhere, restOptions, clientSDK);
2121
return query.execute();
2222
}
2323

2424
// get is just like find but only queries an objectId.
25-
const get = (config, auth, className, objectId, restOptions) => {
25+
const get = (config, auth, className, objectId, restOptions, clientSDK) => {
2626
enforceRoleSecurity('get', className, auth);
27-
let query = new RestQuery(config, auth, className, { objectId }, restOptions);
27+
let query = new RestQuery(config, auth, className, { objectId }, restOptions, clientSDK);
2828
return query.execute();
2929
}
3030

3131
// Returns a promise that doesn't resolve to any useful value.
32-
function del(config, auth, className, objectId) {
32+
function del(config, auth, className, objectId, clientSDK) {
3333
if (typeof objectId !== 'string') {
3434
throw new Parse.Error(Parse.Error.INVALID_JSON,
3535
'bad objectId');
@@ -92,16 +92,16 @@ function del(config, auth, className, objectId) {
9292
}
9393

9494
// Returns a promise for a {response, status, location} object.
95-
function create(config, auth, className, restObject) {
95+
function create(config, auth, className, restObject, clientSDK) {
9696
enforceRoleSecurity('create', className, auth);
97-
var write = new RestWrite(config, auth, className, null, restObject);
97+
var write = new RestWrite(config, auth, className, null, restObject, clientSDK);
9898
return write.execute();
9999
}
100100

101101
// Returns a promise that contains the fields of the update that the
102102
// REST API is supposed to return.
103103
// Usually, this is just updatedAt.
104-
function update(config, auth, className, objectId, restObject) {
104+
function update(config, auth, className, objectId, restObject, clientSDK) {
105105
enforceRoleSecurity('update', className, auth);
106106

107107
return Promise.resolve().then(() => {
@@ -117,7 +117,7 @@ function update(config, auth, className, objectId, restObject) {
117117
originalRestObject = response.results[0];
118118
}
119119

120-
var write = new RestWrite(config, auth, className, {objectId: objectId}, restObject, originalRestObject);
120+
var write = new RestWrite(config, auth, className, {objectId: objectId}, restObject, originalRestObject, clientSDK);
121121
return write.execute();
122122
});
123123
}

0 commit comments

Comments
 (0)