Skip to content

Commit ca46845

Browse files
authored
Merge pull request #6012 from Countly/sdk_sc_changes
[sdk] reset server conf & location tracking
2 parents 94e42f5 + b6496ac commit ca46845

File tree

30 files changed

+1042
-58
lines changed

30 files changed

+1042
-58
lines changed

.github/workflows/main.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,72 @@ jobs:
341341
mkdir -p screenshots videos
342342
tar zcvf "$ARTIFACT_ARCHIVE_NAME" screenshots videos
343343
curl -o /tmp/uploader.log -u "${{ secrets.BOX_UPLOAD_AUTH }}" ${{ secrets.BOX_UPLOAD_PATH }} -T "$ARTIFACT_ARCHIVE_NAME"
344+
345+
ui-test-sdk:
346+
runs-on: ubuntu-latest
347+
348+
services:
349+
mongodb:
350+
image: mongo:8.0
351+
options: >-
352+
--health-cmd mongosh
353+
--health-interval 10s
354+
--health-timeout 5s
355+
--health-retries 5
356+
ports:
357+
- 27017:27017
358+
359+
container:
360+
image: countly/countly-core:pipelines-${{ inputs.custom_tag || github.base_ref || github.ref_name }}
361+
env:
362+
COUNTLY_CONFIG__MONGODB_HOST: mongodb
363+
COUNTLY_CONFIG_API_PREVENT_JOBS: true
364+
365+
steps:
366+
- uses: actions/checkout@v2
367+
368+
- name: Install Chrome
369+
shell: bash
370+
run: |
371+
apt update
372+
apt install -y libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 xauth xvfb wget
373+
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -O /tmp/chrome.deb
374+
apt install -y /tmp/chrome.deb
375+
376+
- name: Copy code
377+
shell: bash
378+
run: cp -rf ./* /opt/countly
379+
380+
- name: Prepare files to use correct MongoDB host
381+
shell: bash
382+
run: "sed -i 's/mongosh --quiet/mongosh --host mongodb --quiet/' /opt/countly/bin/backup/import_events.sh && sed -i 's/mongoimport --db/mongoimport --host mongodb --db/' /opt/countly/bin/backup/import_events.sh"
383+
384+
- name: NPM install
385+
shell: bash
386+
working-directory: /opt/countly
387+
run: npm install
388+
389+
- name: Prepare environment
390+
shell: bash
391+
working-directory: /opt/countly
392+
run: |
393+
sed -i 's/port: 3001,/port: 3001, workers: 1,/' /opt/countly/api/config.js
394+
cp "./plugins/plugins.default.json" "/opt/countly/plugins/plugins.json"
395+
npm install
396+
sudo countly task dist-all
397+
bash bin/scripts/countly.prepare.ce.tests.sh
398+
cd ui-tests
399+
echo '{"username": "${{ secrets.CYPRESS_USER_USERNAME }}","email": "${{ secrets.CYPRESS_USER_EMAIL }}","password": "${{ secrets.CYPRESS_USER_PASSWORD }}"}' > cypress/fixtures/user.json
400+
sed -i 's/00000000-0000-0000-0000-000000000000/${{ secrets.CYPRESS_KEY }}/g' package.json
401+
cp cypress.config.sample.js cypress.config.js
402+
sed -i 's/000000/${{ secrets.CYPRESS_PROJECT_ID }}/g' cypress.config.js
403+
404+
- name: Run UI tests
405+
shell: bash
406+
working-directory: /opt/countly
407+
run: |
408+
/sbin/my_init &
409+
cd ui-tests
410+
npm install
411+
xvfb-run --auto-servernum --server-args="-screen 0 1280x1024x24" \
412+
npm run cy:run:sdk

frontend/express/public/javascripts/countly/vue/components/helpers.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,10 @@
443443
placement: {
444444
type: String,
445445
default: 'auto'
446+
},
447+
tooltipClass: {
448+
type: String,
449+
default: ''
446450
}
447451
},
448452
computed: {
@@ -453,7 +457,7 @@
453457
};
454458
}
455459
},
456-
template: '<i v-if="tooltip" :class="\'cly-vue-tooltip-icon \' + icon" v-tooltip="tooltipConf"></i>'
460+
template: '<i v-if="tooltip" :class="\'cly-vue-tooltip-icon \' + icon + \' \' + tooltipClass" v-tooltip="tooltipConf"></i>'
457461
}));
458462

459463
Vue.component("cly-remover", countlyBaseComponent.extend({

plugins/sdk/api/api.js

Lines changed: 126 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)