@@ -12,6 +12,49 @@ plugins.register("/permissions/features", function(ob) {
1212
1313( function ( ) {
1414
15+ /**
16+ * @api {get } /o/sdk?method=sc Get SDK config
17+ * @apiName GetSDKConfig
18+ * @apiGroup SDK Config
19+ * @apiPermission app
20+ * @apiDescription Get SDK configuration for this SDK and this user
21+ *
22+ * @apiQuery {String} app_key Application key
23+ *
24+ * @apiSuccess {Object} v - version
25+ * @apiSuccess {Object} t - timestamp
26+ * @apiSuccess {Object} c - sdk config
27+ *
28+ * @apiSuccessExample {json} Success-Response:
29+ * {
30+ "v":1,
31+ "t":1682328445330,
32+ "c":{
33+ "tracking":true,
34+ "networking":true,
35+ "crt":true,
36+ "vt":true,
37+ "st":true,
38+ "cet":true,
39+ "ecz":true,
40+ "cr":true,
41+ "sui":true,
42+ "eqs":true,
43+ "rqs":true,
44+ "czi":true,
45+ "dort":true,
46+ "scui":true,
47+ "lkl":true,
48+ "lvs":true,
49+ "lsv":true,
50+ "lbc":true,
51+ "ltlpt":true,
52+ "ltl":true,
53+ "lt":true,
54+ "rcz":true
55+ }
56+ * }
57+ */
1558 plugins . register ( "/o/sdk" , function ( ob ) {
1659 var params = ob . params ;
1760 if ( params . qstring . method !== "sc" ) {
@@ -36,36 +79,24 @@ plugins.register("/permissions/features", function(ob) {
3679 } ) ;
3780
3881 /**
39- * @api {get } /o?method=sc Get SDK config
40- * @apiName GetSDKConfig
82+ * @api {get } /o?method=config-upload Save SDK config
83+ * @apiName SaveSDKConfig
4184 * @apiGroup SDK Config
42- * @apiPermission app
43- * @apiDescription Get SDK configuration for this SDK and this user
44- *
45- * @apiQuery {String} app_key Application key
46- *
47- * @apiSuccess {Object} v - version
48- * @apiSuccess {Object} t - timestamp
49- * @apiSuccess {Object} c - sdk config
50- *
51- * @apiSuccessExample {json} Success-Response:
85+ * @apiPermission admin
86+ * @apiDescription Save SDK configuration for the given app
87+ *
88+ * @apiQuery {String} app_id Application ID
89+ * @apiQuery {String} config SDK config object
90+ *
91+ * @apiSuccess {json} Success-Response:
5292 * {
53- "v":1,
54- "t":1682328445330,
55- "c":{
56- "tracking":false,
57- "networking":false,
58- "crashes":false,
59- "views":false,
60- "heartbeat":61,
61- "event_queue":11,
62- "request_queue":1001
63- }
93+ * "result": "Success"
6494 * }
6595 */
6696 plugins . register ( "/o" , function ( ob ) {
6797 var params = ob . params ;
6898
99+ // returns server config for the given app
69100 if ( params . qstring . method === "sdk-config" ) {
70101 validateRead ( params , FEATURE_NAME , function ( ) {
71102 getSDKConfig ( params ) . then ( function ( res ) {
@@ -78,6 +109,77 @@ plugins.register("/permissions/features", function(ob) {
78109
79110 return true ;
80111 }
112+
113+ // saves the given server configuration for the given app
114+ if ( params . qstring . method === "config-upload" ) {
115+ return new Promise ( function ( resolve ) {
116+ validateUpdate ( params , FEATURE_NAME , function ( ) {
117+ var uploadConfig = params . qstring . config ;
118+ if ( uploadConfig && typeof uploadConfig === "string" ) {
119+ try {
120+ uploadConfig = JSON . parse ( uploadConfig ) ;
121+ }
122+ catch ( ex ) {
123+ common . returnMessage ( params , 400 , 'Invalid config format' ) ;
124+ return resolve ( ) ;
125+ }
126+ }
127+
128+ if ( ! uploadConfig || typeof uploadConfig !== "object" ) {
129+ common . returnMessage ( params , 400 , 'Config must be a valid object' ) ;
130+ return resolve ( ) ;
131+ }
132+
133+ var configToSave = uploadConfig . c || uploadConfig ; // incase they provide the config object directly
134+ var validOptions = [
135+ "tracking" ,
136+ "networking" ,
137+ "crt" ,
138+ "vt" ,
139+ "st" ,
140+ "cet" ,
141+ "ecz" ,
142+ "cr" ,
143+ "sui" ,
144+ "eqs" ,
145+ "rqs" ,
146+ "czi" ,
147+ "dort" ,
148+ "scui" ,
149+ "lkl" ,
150+ "lvs" ,
151+ "lsv" ,
152+ "lbc" ,
153+ "ltlpt" ,
154+ "ltl" ,
155+ "lt" ,
156+ "rcz"
157+ ] ;
158+ for ( var key in configToSave ) {
159+ if ( validOptions . indexOf ( key ) === - 1 ) {
160+ delete configToSave [ key ] ;
161+ }
162+ }
163+
164+ common . outDb . collection ( 'sdk_configs' ) . updateOne (
165+ { _id : params . qstring . app_id + "" } ,
166+ { $set : { config : configToSave } } ,
167+ { upsert : true } ,
168+ function ( err ) {
169+ if ( err ) {
170+ common . returnMessage ( params , 500 , 'Error saving config to database' ) ;
171+ }
172+ else {
173+ common . returnOutput ( params , { result : 'Success' } ) ;
174+ }
175+ resolve ( ) ;
176+ }
177+ ) ;
178+ } ) ;
179+ } ) ;
180+ }
181+
182+ return false ;
81183 } ) ;
82184
83185 plugins . register ( "/i/sdk-config" , function ( ob ) {
@@ -359,7 +461,7 @@ plugins.register("/permissions/features", function(ob) {
359461 } ) ;
360462
361463 /**
362- * Updated SDK config
464+ * Updates SDK config (used internally when configuration is changed in the dashboard)
363465 * @param {params } params - request params
364466 * @returns {void }
365467 */
0 commit comments