diff --git a/README.md b/README.md index 99f334be8c..a54c7ce8c2 100644 --- a/README.md +++ b/README.md @@ -143,7 +143,10 @@ Currently the following information is reported: * If a JavaScript framework (currently React Native and Electron) is used and its version. * Which JavaScript engine is being used. * Node.js version number. - * An anonymous machine identifier and hashed application path to aggregate the other information on. + * TypeScript version if used. + * An anonymous machine identifier and hashed application name to aggregate the other information on. + +Moreover, we unconditionally write various constants to a file which we might use at runtime. ## Code of Conduct diff --git a/packages/realm/bindgen/js_opt_in_spec.yml b/packages/realm/bindgen/js_opt_in_spec.yml index 84ea3d85c3..8153a99980 100644 --- a/packages/realm/bindgen/js_opt_in_spec.yml +++ b/packages/realm/bindgen/js_opt_in_spec.yml @@ -157,6 +157,7 @@ records: - device_version - framework_name - framework_version + - bundle_id AppConfig: fields: diff --git a/packages/realm/bindgen/vendor/realm-core b/packages/realm/bindgen/vendor/realm-core index 85915d8a85..d43218fa1f 160000 --- a/packages/realm/bindgen/vendor/realm-core +++ b/packages/realm/bindgen/vendor/realm-core @@ -1 +1 @@ -Subproject commit 85915d8a855bfdc713b59df9008661c540fe2c8d +Subproject commit d43218fa1fe657357a7bd87ab51aa09bac005031 diff --git a/packages/realm/package.json b/packages/realm/package.json index 0db2d45281..5c4d1706cc 100644 --- a/packages/realm/package.json +++ b/packages/realm/package.json @@ -33,9 +33,11 @@ }, "./scripts/submit-analytics": "./scripts/submit-analytics.mjs", "./react-native.config.js": "./react-native.config.js", - "./package.json": "./package.json" + "./package.json": "./package.json", + "./realm-constants.json": "./realm-constants.json" }, "files": [ + "dependencies.list", "dist", "index.node.js", "index.react-native.js", diff --git a/packages/realm/realm-constants.json b/packages/realm/realm-constants.json new file mode 100644 index 0000000000..028a2d25f4 --- /dev/null +++ b/packages/realm/realm-constants.json @@ -0,0 +1,3 @@ +{ + "REALM_ANONYMIZED_BUNDLE_ID": "" +} diff --git a/packages/realm/rollup.config.mjs b/packages/realm/rollup.config.mjs index bbc0164465..954043190f 100644 --- a/packages/realm/rollup.config.mjs +++ b/packages/realm/rollup.config.mjs @@ -70,7 +70,7 @@ export default [ outputToFilesystem: true, }), ], - external: ["bson", "debug", "node-fetch", "node:module", "node:fs", "node:path"], + external: ["bson", "debug", "node-fetch", "node:module", "node:fs", "node:path", "realm/realm-constants.json"], }, { input: "src/platform/react-native/index.ts", @@ -94,7 +94,7 @@ export default [ outputToFilesystem: true, }), ], - external: ["bson", "debug", "react-native"], + external: ["bson", "debug", "react-native", "realm/realm-constants.json"], }, { input: "src/index.ts", @@ -111,6 +111,6 @@ export default [ }, }), ], - external: ["bson"], + external: ["bson", "realm/realm-constants.json"], }, ]; diff --git a/packages/realm/scripts/submit-analytics.mjs b/packages/realm/scripts/submit-analytics.mjs index 6b7a206c67..c8d9f6cd1d 100644 --- a/packages/realm/scripts/submit-analytics.mjs +++ b/packages/realm/scripts/submit-analytics.mjs @@ -147,6 +147,17 @@ function getRealmCoreVersion() { return dependenciesList.find((e) => e[0] === "REALM_CORE_VERSION")[1]; } +/** + * Save the anonymized bundle ID for later usage at runtime. + */ +function saveBundleId(anonymizedBundleId) { + const localPath = path.resolve(path.join(getProjectRoot(), "node_modules", "realm")); + fs.mkdirSync(localPath, { recursive: true }); + const realmConstantsFile = path.resolve(path.join(localPath, "realm-constants.json")); + const realmConstants = { REALM_ANONYMIZED_BUNDLE_ID: anonymizedBundleId }; + fs.writeFileSync(realmConstantsFile, JSON.stringify(realmConstants)); +} + /** * Determines if `npm` or `yarn` is used. * @returns An array with two elements: method and version @@ -183,6 +194,8 @@ async function collectPlatformData(packagePath = getProjectRoot()) { if (packageJson.name) { bundleId = packageJson["name"]; } + const anonymizedBundleId = sha256(bundleId); + saveBundleId(anonymizedBundleId); if (packageJson.dependencies && packageJson.dependencies["react-native"]) { framework = "react-native"; @@ -262,7 +275,7 @@ async function collectPlatformData(packagePath = getProjectRoot()) { "JS Analytics Version": 3, distinct_id: identifier, "Anonymized Builder Id": sha256(identifier), - "Anonymized Bundle Id": sha256(bundleId), + "Anonymized Bundle Id": anonymizedBundleId, "Realm Version": realmVersion, Binding: "Javascript", Version: packageJson.version, diff --git a/packages/realm/src/platform/node/device-info.ts b/packages/realm/src/platform/node/device-info.ts index 54676e0294..64ea977f16 100644 --- a/packages/realm/src/platform/node/device-info.ts +++ b/packages/realm/src/platform/node/device-info.ts @@ -17,8 +17,10 @@ //////////////////////////////////////////////////////////////////////////// import os from "node:os"; +import process from "node:process"; import { version } from "realm/package.json"; +import { REALM_ANONYMIZED_BUNDLE_ID } from "realm/realm-constants.json"; import { inject } from "../device-info"; @@ -38,6 +40,8 @@ inject({ frameworkName: typeof process.versions.electron === "string" ? "Electron" : "Node.js", frameworkVersion: process.versions.electron || process.version, + + bundleId: REALM_ANONYMIZED_BUNDLE_ID, }; }, }); diff --git a/packages/realm/src/platform/react-native/device-info.ts b/packages/realm/src/platform/react-native/device-info.ts index 6086e8e52d..e46aee2ca7 100644 --- a/packages/realm/src/platform/react-native/device-info.ts +++ b/packages/realm/src/platform/react-native/device-info.ts @@ -19,6 +19,7 @@ import { Platform } from "react-native"; import { version } from "realm/package.json"; +import { REALM_ANONYMIZED_BUNDLE_ID } from "realm/realm-constants.json"; import { inject } from "../device-info"; import { JsPlatformHelpers } from "../../binding"; @@ -75,6 +76,8 @@ inject({ frameworkName: "react-native", frameworkVersion: getReactNativeVersion(), + + bundleId: REALM_ANONYMIZED_BUNDLE_ID, }; }, });