Bug 1963183 - Add buildId to ASRouterTargeting and Nimbus targeting context r=omc-reviewers,nimbus-reviewers,emcminn

Differential Revision: https://phabricator.services.mozilla.com/D246994
This commit is contained in:
Beth Rennie
2025-05-06 18:53:50 +00:00
committed by brennie@mozilla.com
parent ea73afd884
commit 25f1aa8bdb
5 changed files with 60 additions and 0 deletions

View File

@@ -19,6 +19,7 @@ Please note that some targeting attributes require stricter controls on the tele
* [blockedCountByType](#blockedcountbytype)
* [browserIsSelected](#browserisselected)
* [browserSettings](#browsersettings)
* [buildId](#buildId)
* [canCreateSelectableProfiles](#cancreateselectableprofiles)
* [creditCardsSaved](#creditcardssaved)
* [currentDate](#currentdate)
@@ -205,6 +206,24 @@ declare const browserSettings: {
}
```
### `buildId`
The build ID (`MOZ_BUILDID`) parsed as a number to allow for comparisons.
#### Examples
* Is the build from at least Jan 01 2025
```java
buildId >= 202501010000
```
#### Definition
```ts
declare const buildId: number;
```
### `currentDate`
The current date at the moment message targeting is checked.

View File

@@ -1199,6 +1199,10 @@ const TargetingGetters = {
get profileGroupId() {
return QueryCache.getters.profileGroupId.get();
},
get buildId() {
return parseInt(AppConstants.MOZ_BUILDID, 10);
},
};
export const ASRouterTargeting = {

View File

@@ -2031,3 +2031,22 @@ add_task(async function check_profileGroupIdTargeting() {
"should select correct item by profile group id"
);
});
add_task(async function test_buildId() {
is(
typeof ASRouterTargeting.Environment.buildId,
"number",
"Should return a number"
);
const message = {
id: "foo",
// Later than January 2025
targeting: `buildId >= 20251010000`,
};
is(
await ASRouterTargeting.findMatchingMessage({ messages: [message] }),
message,
"should select correct item when filtering by build ID"
);
});

View File

@@ -99,6 +99,8 @@ function assertType(expectedType, attribute) {
* type.
*/
const typeAssertions = {
integer: attribute =>
assertType("number", attribute) && Number.isSafeInteger(attribute),
string: attribute => assertType("string", attribute),
boolean: attribute => assertType("boolean", attribute),
quantity: attribute => Math.floor(assertType("number", attribute)),
@@ -133,6 +135,7 @@ export const ATTRIBUTE_TRANSFORMS = Object.freeze({
browserSettings: pickWith({
update: pick("channel"),
}),
buildId: typeAssertions.integer,
currentDate: typeAssertions.date,
defaultPDFHandler: pick("knownBrowser", "registered"),
distributionId: typeAssertions.string,

View File

@@ -28,12 +28,14 @@ nimbus_targeting_environment:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1898394
- https://bugzilla.mozilla.org/show_bug.cgi?id=1949813
- https://bugzilla.mozilla.org/show_bug.cgi?id=1963160
- https://bugzilla.mozilla.org/show_bug.cgi?id=1963183
data_reviews: &targeting_context_data_reviews
- https://bugzilla.mozilla.org/show_bug.cgi?id=1928107
- https://bugzilla.mozilla.org/show_bug.cgi?id=1937207
- https://bugzilla.mozilla.org/show_bug.cgi?id=1898394
- https://bugzilla.mozilla.org/show_bug.cgi?id=1949813
- https://bugzilla.mozilla.org/show_bug.cgi?id=1963160
- https://bugzilla.mozilla.org/show_bug.cgi?id=1963183
notification_emails: &targeting_context_notification_emails
- beth@mozilla.com
- project-nimbus@mozilla.com
@@ -107,6 +109,7 @@ nimbus_targeting_environment:
- "archBits"
- "attributionData"
- "browserSettings"
- "buildId"
- "currentDate"
- "defaultPDFHandler"
- "distributionId"
@@ -335,6 +338,18 @@ nimbus_targeting_context:
channel:
type: string
build_id:
bugs: *targeting_context_bugs
data_reviews: *targeting_context_data_reviews
expires: *targeting_context_expiry
notification_emails: *targeting_context_notification_emails
send_in_pings: *targeting_context_pings
description: The Build ID.
data_sensitivity:
- technical
type: quantity
unit: build ID
current_date:
bugs: *targeting_context_bugs
data_reviews: *targeting_context_data_reviews