Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 6 additions & 4 deletions apps/klaviyo/src/locations/ConfigScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
getEntryKlaviyoFieldMappings,
setEntryKlaviyoFieldMappings,
} from '../utils/field-mappings';
import { getOrgIdForSdk } from '../utils/sdk-helpers';

// Helper to ensure klaviyoFieldMappings entry exists
const ensureKlaviyoFieldMappingsEntry = async (sdk: ConfigAppSDK) => {
Expand Down Expand Up @@ -138,6 +139,7 @@ const ConfigScreen = () => {
const [isDisconnecting, setIsDisconnecting] = useState(false);
const popupWindowRef = useRef<Window | null>(null);
const checkWindowIntervalRef = useRef<number | null>(null);
const orgId = getOrgIdForSdk(sdk);

// Check Klaviyo connection status with polling to handle race conditions
const checkKlaviyoStatus = async (
Expand All @@ -150,7 +152,7 @@ const ConfigScreen = () => {
try {
console.log(`Checking Klaviyo connection status (attempt ${attempt}/${maxRetries})...`);
const appActions = await sdk.cma.appAction.getMany({
organizationId: sdk.ids.organization,
organizationId: orgId,
appDefinitionId: sdk.ids.app,
});

Expand Down Expand Up @@ -229,7 +231,7 @@ const ConfigScreen = () => {
const appDefinitionId = sdk.ids.app;
// call app action to complete oauth
const appActions = await sdk.cma.appAction.getMany({
organizationId: sdk.ids.organization,
organizationId: orgId,
appDefinitionId,
});
console.log('appActions', appActions);
Expand Down Expand Up @@ -282,7 +284,7 @@ const ConfigScreen = () => {

try {
const appActions = await sdk.cma.appAction.getMany({
organizationId: sdk.ids.organization,
organizationId: orgId,
appDefinitionId: sdk.ids.app,
});

Expand Down Expand Up @@ -323,7 +325,7 @@ const ConfigScreen = () => {
setIsDisconnecting(true);
try {
const appActions = await sdk.cma.appAction.getMany({
organizationId: sdk.ids.organization,
organizationId: orgId,
appDefinitionId: sdk.ids.app,
});
const disconnectAppAction = appActions.items.find((action) => action.name === 'Disconnect');
Expand Down
8 changes: 8 additions & 0 deletions apps/klaviyo/src/utils/sdk-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,11 @@ export const getGlobalSDK = async (retries = MAX_RETRIES): Promise<any | null> =
}, RETRY_DELAY);
});
};

const APP_ORGANIZATION_ID = '5EJGHo8tYJcjnEhYWDxivp';
const APP_DEFINITION_ID = '2x4lsvuxPAGS2UUHwWVYee';

export const getOrgIdForSdk = (sdk: any) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sdk param could use a proper type

Suggested change
export const getOrgIdForSdk = (sdk: any) => {
export const getOrgIdForSdk = (sdk: ConfigAppSDK) => {

const isMarketplaceVersion = sdk.ids.app === APP_DEFINITION_ID;
return isMarketplaceVersion ? APP_ORGANIZATION_ID : sdk.ids.organization;
};
Loading