Skip to content
Merged
20 changes: 18 additions & 2 deletions src/apis/nimbus.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ ChromeUtils.defineLazyGetter(this, "_ExperimentAPI", () => {
}
});

ChromeUtils.defineLazyGetter(this, "TargetingContextRecorder", () => {
try {
return ChromeUtils.importESModule(
"moz-src:///toolkit/components/nimbus/lib/TargetingContextRecorder.sys.mjs",
);
} catch {
return ChromeUtils.importESModule(
"resource://nimbus/lib/TargetingContextRecorder.sys.mjs",
);
}
});

ChromeUtils.defineLazyGetter(
this,
"ExperimentAPI",
Expand Down Expand Up @@ -296,7 +308,7 @@ var nimbus = class extends ExtensionAPI {
ExperimentManager.createTargetingContext(),
);

const targetingParameters = {
const values = {
...environment,
...localContext,
// This code is based on the implementation from:
Expand All @@ -309,7 +321,11 @@ var nimbus = class extends ExtensionAPI {
os: ClientEnvironmentBase.os,
};

return targetingParameters;
return {
attrs: Object.keys(TargetingContextRecorder.ATTRIBUTE_TRANSFORMS),
prefs: Object.keys(TargetingContextRecorder.PREFS),
values,
};
},

async updateRecipes() {
Expand Down
12 changes: 9 additions & 3 deletions src/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ declare module "mozjexl/lib/parser/Parser" {
type Identifier = {
type: "Identifier";
value: string;
from?: Identifier;
from?: ASTNode;
};

type ArrayLiteral = {
Expand Down Expand Up @@ -136,6 +136,12 @@ type CurrentCollection = {
prefValue: string;
};

type ClientContextValue = object | string | boolean | number | Date | undefined;
type ClientContext = {
attrs: string[];
prefs: string[];
values: Record<string, ClientContextValue>;
};
declare namespace browser.experiments.nimbus {
function enrollInExperiment(
jsonData: object,
Expand All @@ -155,9 +161,9 @@ declare namespace browser.experiments.nimbus {

function setCollection(collectionId: string): Promise<void>;

function evaluateJEXL(expression: string, context: object): Promise<object>;
function evaluateJEXL(expression: string, context: object): Promise<unknown>;

function getClientContext(): Promise<object>;
function getClientContext(): Promise<ClientContext>;

function injectInactiveEnrollment(
recipe: object,
Expand Down
Loading
Loading