Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a transformer to enforce current terminology in reportEvent without breaking Mixpanel events #8774

Merged
merged 19 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/__snapshots__/Storyshots.test.js.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/activation/useActivateMod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ type ActivationSource = "marketplace" | "extensionConsole";

function selectActivateEventData(modDefinition: ModDefinition) {
return {
blueprintId: modDefinition.metadata.id,
extensions: modDefinition.extensionPoints.map((x) => x.label),
modId: modDefinition.metadata.id,
modComponents: modDefinition.extensionPoints.map((x) => x.label),
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/background/executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ const runBrickMock = jest.mocked(runBrick);
const optionsFactory = define<RemoteBrickOptions>({
ctxt: () => ({}),
messageContext: (i: number) => ({
extensionId: uuidSequence(i),
modComponentId: uuidSequence(i),
}),
meta: derive<RemoteBrickOptions, RemoteBrickOptions["meta"]>(
(options) => ({
extensionId: options.messageContext!.extensionId,
extensionId: options.messageContext!.modComponentId,
runId: null,
branches: [],
}),
Expand Down
6 changes: 3 additions & 3 deletions src/background/messenger/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import * as registry from "@/registry/packageRegistry";
import serviceRegistry from "@/integrations/registry";
import { getUserData } from "@/auth/authStorage";
import {
clearExtensionDebugLogs,
clearModComponentDebugLogs,
clearLog,
clearLogs,
recordError,
Expand Down Expand Up @@ -108,7 +108,7 @@ declare global {
RECORD_ERROR: typeof recordError;
CLEAR_LOGS: typeof clearLogs;
CLEAR_LOG: typeof clearLog;
CLEAR_EXTENSION_DEBUG_LOGS: typeof clearExtensionDebugLogs;
CLEAR_EXTENSION_DEBUG_LOGS: typeof clearModComponentDebugLogs;
grahamlangford marked this conversation as resolved.
Show resolved Hide resolved

LOCATE_SERVICES_FOR_ID: typeof locator.locateAllForService;
LOCATE_SERVICE: typeof locator.locate;
Expand Down Expand Up @@ -181,7 +181,7 @@ export default function registerMessenger(): void {
RECORD_ERROR: recordError,
CLEAR_LOGS: clearLogs,
CLEAR_LOG: clearLog,
CLEAR_EXTENSION_DEBUG_LOGS: clearExtensionDebugLogs,
CLEAR_EXTENSION_DEBUG_LOGS: clearModComponentDebugLogs,

LOCATE_SERVICES_FOR_ID: locator.locateAllForService.bind(locator),
LOCATE_SERVICE: locator.locate.bind(locator),
Expand Down
2 changes: 1 addition & 1 deletion src/background/removeModComponentForEveryTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ export async function removeModComponentForEveryTab(
});
await uninstallContextMenu({ extensionId: modComponentId });
await clearModComponentTraces(modComponentId);
await clearLog({ extensionId: modComponentId });
await clearLog({ modComponentId });
grahamlangford marked this conversation as resolved.
Show resolved Hide resolved
}
4 changes: 2 additions & 2 deletions src/background/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ async function getIntegrationMessageContext(
}

return {
serviceId: config.serviceId,
serviceVersion: resolvedIntegration?.version,
integrationId: config.serviceId,
integrationVersion: resolvedIntegration?.version,
authId: config.id,
};
}
Expand Down
14 changes: 7 additions & 7 deletions src/bricks/effects/AddDynamicTextSnippet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ describe("AddDynamicTextSnippet", () => {
async (shortcut) => {
const extensionId = uuidv4();
const logger = new ConsoleLogger({
extensionId,
blueprintId: registryIdFactory(),
modComponentId: extensionId,
modId: registryIdFactory(),
});

const pipeline = {
Expand Down Expand Up @@ -81,8 +81,8 @@ describe("AddDynamicTextSnippet", () => {
componentId: extensionId,
context: {
...logger.context,
blockId: brick.id,
blockVersion: expect.toBeString(),
brickId: brick.id,
brickVersion: expect.toBeString(),
label: brick.name,
},
},
Expand All @@ -98,7 +98,7 @@ describe("AddDynamicTextSnippet", () => {
"passes preview directly: %s",
async (preview) => {
const extensionId = uuidv4();
const logger = new ConsoleLogger({ extensionId });
const logger = new ConsoleLogger({ modComponentId: extensionId });

const pipeline = {
id: brick.id,
Expand Down Expand Up @@ -127,8 +127,8 @@ describe("AddDynamicTextSnippet", () => {
componentId: extensionId,
context: {
...logger.context,
blockId: brick.id,
blockVersion: expect.toBeString(),
brickId: brick.id,
brickVersion: expect.toBeString(),
label: brick.name,
},
},
Expand Down
4 changes: 2 additions & 2 deletions src/bricks/effects/AddDynamicTextSnippet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ class AddDynamicTextSnippet extends EffectABC {
return;
}

if (logger.context.extensionId == null) {
if (logger.context.modComponentId == null) {
throw new Error("Must be run in the context of a mod");
}

// Counter to keep track of the action run number for tracing
let counter = 0;

platform.snippetShortcutMenu.register({
componentId: logger.context.extensionId,
componentId: logger.context.modComponentId,
context: logger.context,
// Trim leading command key in shortcut to be resilient to user input
shortcut: normalizeShortcut(shortcut),
Expand Down
4 changes: 2 additions & 2 deletions src/bricks/effects/AddQuickBarAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ class AddQuickBarAction extends EffectABC {
let counter = 0;

// Expected parent id from QuickBarProviderExtensionPoint
const parentId = `provider-${logger.context.extensionId}`;
const parentId = `provider-${logger.context.modComponentId}`;

const action: CustomAction = {
// XXX: old actions will still appear in the quick bar unless the extension point clears out the old actions
id: `${logger.context.extensionId}-${title}`,
id: `${logger.context.modComponentId}-${title}`,
// Additional metadata, for enabling clearing out old actions
modComponentRef: mapMessageContextToModComponentRef(logger.context),
// Can only provide a parent if the parent exists
Expand Down
2 changes: 1 addition & 1 deletion src/bricks/effects/AddTextSnippets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe("AddTextSnippets", () => {
title: "Test",
preview: "test text",
handler: expect.toBeFunction(),
componentId: options.logger.context.extensionId,
componentId: options.logger.context.modComponentId,
context: options.logger.context,
},
]);
Expand Down
4 changes: 2 additions & 2 deletions src/bricks/effects/AddTextSnippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ class AddTextSnippets extends EffectABC {
return;
}

if (logger.context.extensionId == null) {
if (logger.context.modComponentId == null) {
throw new Error("Must be run in the context of a mod component");
}

for (const { shortcut, title, text } of snippets) {
platform.snippetShortcutMenu.register({
componentId: logger.context.extensionId,
componentId: logger.context.modComponentId,
context: logger.context,
shortcut: normalizeShortcut(shortcut),
title,
Expand Down
4 changes: 2 additions & 2 deletions src/bricks/effects/assignModVariable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ const modId = validateRegistryId("test/123");
const brick = new AssignModVariable();

const logger = new ConsoleLogger({
extensionId: modComponentId,
blueprintId: modId,
modComponentId,
modId,
});

const brickOptions = brickOptionsFactory({ logger });
Expand Down
2 changes: 1 addition & 1 deletion src/bricks/effects/assignModVariable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class AssignModVariable extends EffectABC {
}>,
{ logger }: BrickOptions,
): Promise<void> {
const { blueprintId: modId, extensionId: modComponentId } = logger.context;
const { modId, modComponentId } = logger.context;

setState({
namespace: StateNamespaces.MOD,
Expand Down
2 changes: 1 addition & 1 deletion src/bricks/effects/attachAutocomplete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { brickOptionsFactory } from "@/testUtils/factories/runtimeFactories";
const brick = new AttachAutocomplete();

const logger = new ConsoleLogger({
extensionId: uuidSequence(0),
modComponentId: uuidSequence(0),
});

describe("AttachAutocomplete", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/bricks/effects/customEvent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { brickOptionsFactory } from "@/testUtils/factories/runtimeFactories";
const brick = new CustomEventEffect();

const logger = new ConsoleLogger({
extensionId: uuidSequence(0),
modComponentId: uuidSequence(0),
});

describe("CustomEventEffect", () => {
Expand Down
18 changes: 9 additions & 9 deletions src/bricks/effects/pageState.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ describe("@pixiebrix/state/get", () => {
test("default to blueprint state", async () => {
const brick = new GetPageState();
const logger = new ConsoleLogger({
extensionId: uuidv4(),
blueprintId: validateRegistryId("test/123"),
modComponentId: uuidv4(),
modId: validateRegistryId("test/123"),
});
await brick.transform(
unsafeAssumeValidArg({}),
Expand All @@ -53,8 +53,8 @@ describe("@pixiebrix/state/set", () => {
test("shallow merge", async () => {
const brick = new SetPageState();
const logger = new ConsoleLogger({
extensionId: uuidv4(),
blueprintId: validateRegistryId("test/123"),
modComponentId: uuidv4(),
modId: validateRegistryId("test/123"),
});

let result = await brick.transform(
Expand All @@ -78,8 +78,8 @@ describe("@pixiebrix/state/set", () => {

const brick = new SetPageState();
const logger = new ConsoleLogger({
extensionId: uuidv4(),
blueprintId: validateRegistryId("test/123"),
modComponentId: uuidv4(),
modId: validateRegistryId("test/123"),
});

const original = {
Expand Down Expand Up @@ -164,8 +164,8 @@ describe("set and get", () => {
const setState = new SetPageState();
const getState = new GetPageState();
const logger = new ConsoleLogger({
extensionId: uuidv4(),
blueprintId: validateRegistryId("test/123"),
modComponentId: uuidv4(),
modId: validateRegistryId("test/123"),
});

await setState.transform(
Expand Down Expand Up @@ -196,7 +196,7 @@ describe("set and get", () => {
const setState = new SetPageState();
const getState = new GetPageState();
const logger = new ConsoleLogger({
extensionId: uuidv4(),
modComponentId: uuidv4(),
});

await setState.transform(
Expand Down
4 changes: 2 additions & 2 deletions src/bricks/effects/pageState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class SetPageState extends TransformerABC {
}>,
{ logger, platform }: BrickOptions,
): Promise<JsonObject> {
const { blueprintId, extensionId } = logger.context;
const { modId: blueprintId, modComponentId: extensionId } = logger.context;
grahamlangford marked this conversation as resolved.
Show resolved Hide resolved

return platform.state.setState({
namespace,
Expand Down Expand Up @@ -205,7 +205,7 @@ export class GetPageState extends TransformerABC {
}: BrickArgs<{ namespace?: StateNamespace }>,
{ logger, platform }: BrickOptions,
): Promise<JsonObject> {
const { blueprintId: modId, extensionId: modComponentId } = logger.context;
const { modId, modComponentId } = logger.context;

return platform.state.getState({
namespace,
Expand Down
2 changes: 1 addition & 1 deletion src/bricks/effects/sidebarEffects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class ShowSidebar extends EffectABC {
sidebarController.updateSidebar({
force: forcePanel,
panelHeading,
blueprintId: logger.context.blueprintId,
blueprintId: logger.context.modId,
}),
);
}
Expand Down
7 changes: 5 additions & 2 deletions src/bricks/effects/tourEffect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class TourEffect extends EffectABC {
);
}

const { extensionId } = logger.context;
const { modComponentId } = logger.context;
const abortController = new AbortController();
const stylesheetLink = await injectStylesheet(stylesheetUrl);

Expand Down Expand Up @@ -166,7 +166,10 @@ export class TourEffect extends EffectABC {
);
}

assertNotNullish(extensionId, "extensionId is required to run a tour");
assertNotNullish(
modComponentId,
"modComponentId is required to run a tour",
);

const tour = introJs()
.setOptions({
Expand Down
4 changes: 2 additions & 2 deletions src/bricks/renderers/customForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,8 @@ describe("CustomFormRenderer", () => {
expect(
getState({
namespace: StateNamespaces.MOD,
modComponentId: options.logger.context.extensionId,
modId: options.logger.context.blueprintId,
modComponentId: options.logger.context.modComponentId,
modId: options.logger.context.modId,
}),
).toStrictEqual({
name: value,
Expand Down
6 changes: 3 additions & 3 deletions src/bricks/renderers/customForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ export class CustomFormRenderer extends RendererABC {
}>,
{ logger, runPipeline, platform }: BrickOptions,
): Promise<ComponentRef> {
if (logger.context.extensionId == null) {
throw new Error("extensionId is required");
if (logger.context.modComponentId == null) {
throw new Error("modComponentId is required");
}

// Redundant with the JSON Schema input validation for `required`. But keeping here for clarity
Expand All @@ -311,7 +311,7 @@ export class CustomFormRenderer extends RendererABC {
assumeNotNullish_UNSAFE(recordId);
}

const { blueprintId, extensionId } = logger.context;
const { modId: blueprintId, modComponentId: extensionId } = logger.context;

const initialData = await getInitialData(storage, recordId, {
blueprintId,
Expand Down
2 changes: 1 addition & 1 deletion src/bricks/transformers/RunBrickByIdTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class RunBrickByIdTransformer extends TransformerABC {
const { logger, ...otherOptions } = options;

return brick.run(rawArguments as BrickArgs, {
logger: logger.childLogger({ blockId: brick.id }),
logger: logger.childLogger({ brickId: brick.id }),
...otherOptions,
});
}
Expand Down
Loading
Loading