Skip to content

Commit

Permalink
Merge pull request #113 from Countly/staging
Browse files Browse the repository at this point in the history
Staging 24.10.1
  • Loading branch information
turtledreams authored Dec 20, 2024
2 parents a25b91d + 84f8354 commit 37b2723
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 16 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 24.10.1
- Added a new method `set_id(newDeviceId)` for managing device ID changes according to the device ID Type
- Added `DeviceIdType` enums to be used to evaluate the device ID type.
- Added reserved keys for user properties

## 24.10.0
- Default max segmentation value count changed from 30 to 100
- Mitigated an issue where SDK could create an unintended dump file
Expand Down
5 changes: 4 additions & 1 deletion lib/countly-bulk-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,10 @@ function CountlyBulkUser(conf) {
var change_custom_property = function(key, value, mod) {
key = cc.truncateSingleValue(key, conf.maxKeyLength, "change_custom_property");
value = cc.truncateSingleValue(value, conf.maxValueSize, "change_custom_property");

if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
cc.log(cc.logLevelEnums.ERROR, "change_custom_property, Provided key is not allowed.");
return;
}
if (!customData[key]) {
customData[key] = {};
}
Expand Down
2 changes: 1 addition & 1 deletion lib/countly-bulk.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ CountlyBulk.StorageTypes = cc.storageTypeEnums;
* });
*/
function CountlyBulk(conf) {
var SDK_VERSION = "24.10.0";
var SDK_VERSION = "24.10.1";
var SDK_NAME = "javascript_native_nodejs_bulk";

var empty_queue_callback = null;
Expand Down
27 changes: 26 additions & 1 deletion lib/countly.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ var CountlyStorage = require("./countly-storage");

var Countly = {};
Countly.StorageTypes = cc.storageTypeEnums;
Countly.DeviceIdType = cc.deviceIdTypeEnums;
Countly.Bulk = Bulk;
(function() {
var SDK_VERSION = "24.10.0";
var SDK_VERSION = "24.10.1";
var SDK_NAME = "javascript_native_nodejs";

var inited = false;
Expand Down Expand Up @@ -627,6 +628,26 @@ Countly.Bulk = Bulk;
return Countly.device_id;
};

/**
* Changes the current device ID according to the device ID type (the preffered method)
* @param {string} newId - new user/device ID to use. Must be a non-empty string value. Invalid values (like null, empty string or undefined) will be rejected
* */
Countly.set_id = function(newId) {
cc.log(cc.logLevelEnums.INFO, `set_id, Changing the device ID to: [${newId}]`);
if (newId === null || newId === undefined || newId === "" || typeof newId !== "string") {
cc.log(cc.logLevelEnums.WARNING, "set_id, The provided id is not a valid ID");
return;
}
if (Countly.get_device_id_type() === cc.deviceIdTypeEnums.DEVELOPER_SUPPLIED) {
// change ID without merge as current ID is Dev supplied, so not first login
Countly.change_id(newId, false);
}
else {
// change ID with merge as current ID is not Dev supplied*/
Countly.change_id(newId, true);
}
};

/**
* Change current user/device id
* @param {string} newId - new user/device ID to use
Expand Down Expand Up @@ -844,6 +865,10 @@ Countly.Bulk = Bulk;
var change_custom_property = function(key, value, mod) {
key = cc.truncateSingleValue(key, Countly.maxKeyLength, "change_custom_property", Countly.debug);
value = cc.truncateSingleValue(value, Countly.maxValueSize, "change_custom_property", Countly.debug);
if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
cc.log(cc.logLevelEnums.ERROR, "change_custom_property, Provided key is not allowed.");
return;
}

if (Countly.check_consent("users")) {
if (!customData[key]) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "countly-sdk-nodejs",
"version": "24.10.0",
"version": "24.10.1",
"description": "Countly NodeJS SDK",
"main": "lib/countly.js",
"directories": {
Expand Down
1 change: 1 addition & 0 deletions test/helpers/helper_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,5 @@ module.exports = {
validateUserDetails,
viewEventValidator,
doesFileStoragePathsExist,
requestBaseParamValidator,
};
102 changes: 102 additions & 0 deletions test/tests_device_id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/* eslint-disable no-console */
var assert = require("assert");
var Countly = require("../lib/countly");
var cc = require("../lib/countly-common");
var hp = require("./helpers/helper_functions");

function initMain(deviceId, eraseID) {
Countly.init({
app_key: "YOUR_APP_KEY",
url: "https://try.count.ly",
device_id: deviceId,
max_events: -1,
// debug: true,
clear_stored_device_id: eraseID,
});
}
function validateSdkGeneratedId(providedDeviceId) {
assert.ok(providedDeviceId);
assert.equal(providedDeviceId.length, 36);
assert.ok(cc.isUUID(providedDeviceId));
assert.equal(Countly.get_device_id(), providedDeviceId);
assert.equal(Countly.get_device_id_type(), Countly.DeviceIdType.SDK_GENERATED);
}

function validateDeveloperSuppliedId(providedDeviceId) {
assert.equal(Countly.get_device_id_type(), Countly.DeviceIdType.DEVELOPER_SUPPLIED);
assert.equal(Countly.get_device_id(), providedDeviceId);
}

describe("Device ID tests", () => {
beforeEach(async() => {
await hp.clearStorage();
});

it("1- set_id with SDK generated to developer supplied", (done) => {
// initialize SDK
initMain(undefined);
validateSdkGeneratedId(Countly.get_device_id());
var oldId = Countly.get_device_id();
Countly.set_id("ID");
validateDeveloperSuppliedId("ID");
setTimeout(() => {
// validate that merge request is generated
var RQ = hp.readRequestQueue();
assert.equal(RQ.length, 1);
hp.requestBaseParamValidator(RQ[0]);
assert.equal(RQ[0].old_device_id, oldId);
done();
}, hp.sWait);
});

it("2- set_id with developer supplied to developer supplied", (done) => {
// initialize SDK
initMain("ID2");
validateDeveloperSuppliedId("ID2");
Countly.set_id("ID");
validateDeveloperSuppliedId("ID");
setTimeout(() => {
// validate that no merge request is generated and the existing request is begin session
var RQ = hp.readRequestQueue();
assert.equal(RQ.length, 1);
hp.sessionRequestValidator(RQ[0]);
done();
}, hp.sWait);
});

it("3- set_id with same custom id", (done) => {
// initialize SDK
initMain("ID");
validateDeveloperSuppliedId("ID");
Countly.set_id("ID");
validateDeveloperSuppliedId("ID");
done();
});

it("4- set_id with same sdk generated id", (done) => {
// initialize SDK
initMain(undefined);
var id = Countly.get_device_id();
validateSdkGeneratedId(id);
Countly.set_id(id);
// so that the type is not converted to developer_supplied
validateSdkGeneratedId(id);
done();
});

it("5- set_id with invalid ids", (done) => {
// initialize SDK
initMain(undefined);
var id = Countly.get_device_id();
validateSdkGeneratedId(id);
Countly.set_id(undefined);
validateSdkGeneratedId(id);

Countly.set_id(null);
validateSdkGeneratedId(id);

Countly.set_id("");
validateSdkGeneratedId(id);
done();
});
});
41 changes: 29 additions & 12 deletions test/tests_device_id_type.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe("Device ID type tests", () => {
beforeEach(async() => {
await hp.clearStorage();
});
it("1.Generated device ID", (done) => {
it("1- Generated device ID", (done) => {
// initialize SDK
initMain(undefined);
Countly.begin_session();
Expand All @@ -71,7 +71,8 @@ describe("Device ID type tests", () => {
done();
}, hp.sWait);
});
it("2.Developer supplied device ID", (done) => {

it("2- Developer supplied device ID", (done) => {
// initialize SDK
initMain("ID");
Countly.begin_session();
Expand All @@ -84,7 +85,8 @@ describe("Device ID type tests", () => {
done();
}, hp.sWait);
});
it("3.With stored dev ID and no new ID", (done) => {

it("3- With stored dev ID and no new ID", (done) => {
// initialize SDK
initMain("ID");
Countly.begin_session();
Expand All @@ -105,7 +107,8 @@ describe("Device ID type tests", () => {
}, hp.sWait);
}, hp.sWait);
});
it("4.With stored dev ID and with new ID", (done) => {

it("4- With stored dev ID and with new ID", (done) => {
// initialize SDK
initMain("ID");
Countly.begin_session();
Expand All @@ -126,7 +129,8 @@ describe("Device ID type tests", () => {
}, hp.sWait);
}, hp.sWait);
});
it("5.With stored generated ID and no new ID", (done) => {

it("5- With stored generated ID and no new ID", (done) => {
// initialize SDK
initMain(undefined);
Countly.begin_session();
Expand All @@ -149,7 +153,8 @@ describe("Device ID type tests", () => {
}, hp.sWait);
}, hp.sWait);
});
it("6.With stored generated ID and with new ID", (done) => {

it("6- With stored generated ID and with new ID", (done) => {
// initialize SDK
initMain(undefined);
Countly.begin_session();
Expand All @@ -172,7 +177,8 @@ describe("Device ID type tests", () => {
}, hp.sWait);
}, hp.sWait);
});
it("7.With stored dev ID and no new ID, flag set", (done) => {

it("7- With stored dev ID and no new ID, flag set", (done) => {
// initialize SDK
initMain("ID");
Countly.begin_session();
Expand All @@ -194,7 +200,7 @@ describe("Device ID type tests", () => {
}, hp.sWait);
});

it("8.With stored dev ID and with new ID, flag set", (done) => {
it("8- With stored dev ID and with new ID, flag set", (done) => {
setTimeout(() => {
// initialize SDK
initMain("ID");
Expand All @@ -217,7 +223,8 @@ describe("Device ID type tests", () => {
}, hp.lWait);
}, hp.lWait);
});
it("9.With stored sdk ID and no new ID, flag set", (done) => {

it("9- With stored sdk ID and no new ID, flag set", (done) => {
// initialize SDK
initMain(undefined);
Countly.begin_session();
Expand All @@ -241,7 +248,7 @@ describe("Device ID type tests", () => {
}, hp.sWait);
});

it("10.With stored sdk ID and with new ID, flag set", (done) => {
it("10- With stored sdk ID and with new ID, flag set", (done) => {
// initialize SDK
initMain(undefined);
Countly.begin_session();
Expand All @@ -264,7 +271,8 @@ describe("Device ID type tests", () => {
}, hp.sWait);
}, hp.sWait);
});
it("11.Change generated device ID", (done) => {

it("11- Change generated device ID", (done) => {
// initialize SDK
initMain(undefined);
Countly.change_id("changedID");
Expand All @@ -280,7 +288,8 @@ describe("Device ID type tests", () => {
}, hp.sWait);
}, hp.sWait);
});
it("12.Change developer supplied device ID", (done) => {

it("12- Change developer supplied device ID", (done) => {
// initialize SDK
initMain("ID");
Countly.change_id("changedID");
Expand All @@ -296,4 +305,12 @@ describe("Device ID type tests", () => {
}, hp.sWait);
}, hp.sWait);
});

it("13- Check new DeviceIdType interface is equal to common interface", (done) => {
setTimeout(() => {
assert.equal(Countly.DeviceIdType.DEVELOPER_SUPPLIED, cc.deviceIdTypeEnums.DEVELOPER_SUPPLIED);
assert.equal(Countly.DeviceIdType.SDK_GENERATED, cc.deviceIdTypeEnums.SDK_GENERATED);
done();
});
});
});

0 comments on commit 37b2723

Please sign in to comment.