Skip to content

Commit 8c4e12d

Browse files
authored
Merge pull request #1024 from contentstack/feature/cmg-774
feat: add is_sso parameter to migration and content type handling fun…
2 parents 80f8ece + 416a6d5 commit 8c4e12d

12 files changed

Lines changed: 88 additions & 32 deletions

File tree

api/package-lock.json

Lines changed: 10 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"html-to-json-parser": "^2.0.1",
5252
"jsdom": "^24.1.0",
5353
"jsonwebtoken": "^9.0.3",
54-
"lodash": "^4.17.21",
54+
"lodash": "^4.18.1",
5555
"lowdb": "^7.0.1",
5656
"mkdirp": "^3.0.1",
5757
"mysql2": "^3.16.2",

api/src/services/migration.service.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,15 @@ const deleteTestStack = async (req: Request): Promise<LoginServiceType> => {
278278
*/
279279
const startTestMigration = async (req: Request): Promise<any> => {
280280
const { orgId, projectId } = req?.params ?? {};
281-
const { region, user_id } = req?.body?.token_payload ?? {};
281+
const { region, user_id, is_sso } = req?.body?.token_payload ?? {};
282+
283+
284+
if (is_sso !== true && is_sso !== false) {
285+
throw new BadRequestError(
286+
'Invalid token_payload.is_sso; expected a boolean value.',
287+
);
288+
}
289+
282290
await ProjectModelLowdb.read();
283291
const project: any = ProjectModelLowdb.chain
284292
.get('projects')
@@ -406,6 +414,7 @@ const startTestMigration = async (req: Request): Promise<any> => {
406414
destinationStackId: project?.current_test_stack_id,
407415
region,
408416
user_id,
417+
is_sso,
409418
});
410419

411420
await marketPlaceAppService?.createAppManifest({
@@ -652,7 +661,14 @@ const startTestMigration = async (req: Request): Promise<any> => {
652661
*/
653662
const startMigration = async (req: Request): Promise<any> => {
654663
const { orgId, projectId } = req?.params ?? {};
655-
const { region, user_id } = req?.body?.token_payload ?? {};
664+
const { region, user_id, is_sso } = req?.body?.token_payload ?? {};
665+
666+
if (typeof is_sso !== 'boolean') {
667+
throw new BadRequestError(
668+
'Missing or invalid SSO flag in token payload: expected boolean "is_sso".',
669+
);
670+
}
671+
656672
await ProjectModelLowdb.read();
657673
const project: any = ProjectModelLowdb.chain
658674
.get('projects')
@@ -793,6 +809,7 @@ const startMigration = async (req: Request): Promise<any> => {
793809
destinationStackId: project?.destination_stack_id,
794810
region,
795811
user_id,
812+
is_sso,
796813
});
797814
await marketPlaceAppService?.createAppManifest({
798815
orgId,

api/src/utils/content-type-creator.utils.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,8 +1026,27 @@ const writeGlobalField = async (schema: any, globalSave: string) => {
10261026
}
10271027
};
10281028

1029-
const existingCtMapper = async ({ keyMapper, contentTypeUid, projectId, region, user_id, type}: any) => {
1029+
const resolveIsSsoFlag = (is_sso: any): boolean => {
1030+
if (typeof is_sso === 'boolean') {
1031+
return is_sso;
1032+
}
1033+
1034+
if (is_sso === 'true') {
1035+
return true;
1036+
}
1037+
1038+
if (is_sso === 'false') {
1039+
return false;
1040+
}
1041+
1042+
throw new Error(
1043+
`Invalid token_payload.is_sso in existingCtMapper; expected boolean, received: ${JSON.stringify(is_sso)}`
1044+
);
1045+
};
1046+
1047+
const existingCtMapper = async ({ keyMapper, contentTypeUid, projectId, region, user_id, is_sso, type}: any) => {
10301048
try {
1049+
const normalizedIsSso = resolveIsSsoFlag(is_sso);
10311050
const ctUid = keyMapper?.[contentTypeUid];
10321051

10331052
if(type === 'global_field') {
@@ -1040,7 +1059,8 @@ const existingCtMapper = async ({ keyMapper, contentTypeUid, projectId, region,
10401059
body: {
10411060
token_payload: {
10421061
region,
1043-
user_id
1062+
user_id,
1063+
is_sso: normalizedIsSso
10441064
}
10451065
}
10461066
}
@@ -1055,7 +1075,8 @@ const existingCtMapper = async ({ keyMapper, contentTypeUid, projectId, region,
10551075
body: {
10561076
token_payload: {
10571077
region,
1058-
user_id
1078+
user_id,
1079+
is_sso: normalizedIsSso
10591080
}
10601081
}
10611082
}
@@ -1141,7 +1162,7 @@ const mergeTwoCts = async (ct: any, mergeCts: any) => {
11411162
return ctData;
11421163
}
11431164

1144-
export const contenTypeMaker = async ({ contentType, destinationStackId, projectId, newStack, keyMapper, region, user_id }: any) => {
1165+
export const contenTypeMaker = async ({ contentType, destinationStackId, projectId, newStack, keyMapper, region, user_id, is_sso }: any) => {
11451166
const marketPlacePath = path.join(process.cwd(), MIGRATION_DATA_CONFIG.DATA, destinationStackId);
11461167
const srcFunc = 'contenTypeMaker';
11471168

@@ -1155,7 +1176,7 @@ export const contenTypeMaker = async ({ contentType, destinationStackId, project
11551176
if (Object?.keys?.(keyMapper)?.length &&
11561177
keyMapper?.[contentType?.contentstackUid] !== "" &&
11571178
keyMapper?.[contentType?.contentstackUid] !== undefined) {
1158-
currentCt = await existingCtMapper({ keyMapper, contentTypeUid: contentType?.contentstackUid, projectId, region, user_id , type: contentType?.type});
1179+
currentCt = await existingCtMapper({ keyMapper, contentTypeUid: contentType?.contentstackUid, projectId, region, user_id, is_sso, type: contentType?.type});
11591180
}
11601181

11611182
// Safe: ensures we never pass undefined to the builder

api/src/utils/field-attacher.utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import ContentTypesMapperModelLowdb from "../models/contentTypesMapper-lowdb.js"
33
import FieldMapperModel from "../models/FieldMapper.js";
44
import { contenTypeMaker } from "./content-type-creator.utils.js";
55

6-
export const fieldAttacher = async ({ projectId, orgId, destinationStackId, region, user_id }: any) => {
6+
export const fieldAttacher = async ({ projectId, orgId, destinationStackId, region, user_id, is_sso }: any) => {
77
await ProjectModelLowdb.read();
88
const projectData: any = ProjectModelLowdb.chain.get("projects").find({
99
id: projectId,
@@ -27,7 +27,7 @@ export const fieldAttacher = async ({ projectId, orgId, destinationStackId, regi
2727
return field;
2828
})
2929
}
30-
await contenTypeMaker({ contentType, destinationStackId, projectId, newStack: projectData?.stackDetails?.isNewStack, keyMapper: projectData?.mapperKeys, region, user_id })
30+
await contenTypeMaker({ contentType, destinationStackId, projectId, newStack: projectData?.stackDetails?.isNewStack, keyMapper: projectData?.mapperKeys, region, user_id, is_sso })
3131
contentTypes?.push?.(contentType);
3232
}
3333
}

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
"postcss": ">=8.4.31",
3232
"serialize-javascript": ">=6.0.2",
3333
"@babel/runtime": ">=7.26.10",
34-
"lodash": "^4.17.23",
35-
"lodash-es": "^4.17.23",
34+
"lodash": "^4.18.1",
35+
"lodash-es": "^4.18.1",
3636
"undici": "^7.18.2",
3737
"tmp": ">=0.2.4",
3838
"minimatch": ">=10.2.3",

ui/package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@
5959
"overrides": {
6060
"@babel/runtime": ">=7.26.10",
6161
"immutable": ">=5.1.5",
62-
"lodash-es": ">=4.17.23",
62+
"lodash-es": "^4.18.1",
6363
"minimatch": ">=10.2.3",
64-
"rollup": ">=4.59.0"
64+
"rollup": ">=4.59.0",
65+
"lodash": "^4.18.1"
6566
},
6667
"eslintConfig": {
6768
"extends": [

ui/src/components/ContentMapper/index.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,11 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
396396
}, [tableData]);
397397

398398
useEffect(() => {
399-
const mappedContentType = contentModels && contentModels?.find((item) => item?.uid === newMigrationData?.content_mapping?.content_type_mapping?.[selectedContentType?.contentstackUid || '']);
399+
const selectedSourceUid = selectedContentType?.contentstackUid || '';
400+
const mappedDestinationUid =
401+
contentTypeMapped?.[selectedSourceUid] ??
402+
newMigrationData?.content_mapping?.content_type_mapping?.[selectedSourceUid];
403+
const mappedContentType = contentModels?.find((item) => item?.uid === mappedDestinationUid);
400404

401405
if (mappedContentType?.uid) {
402406
setOtherContentType((prev) => {
@@ -409,7 +413,12 @@ const ContentMapper = forwardRef(({ handleStepChange }: contentMapperProps, ref:
409413
});
410414
setIsContentDeleted(false);
411415
}
412-
}, [contentTypeMapped, otherCmsTitle, contentModels]);
416+
}, [
417+
contentTypeMapped,
418+
contentModels,
419+
selectedContentType?.contentstackUid,
420+
newMigrationData?.content_mapping?.content_type_mapping
421+
]);
413422

414423
useEffect(() => {
415424
if (isContentDeleted) {

0 commit comments

Comments
 (0)