Skip to content

Commit 9c4881f

Browse files
authored
Merge pull request #1028 from contentstack/dev
Dev
2 parents d0570b9 + 3bfa644 commit 9c4881f

22 files changed

Lines changed: 5094 additions & 2827 deletions

File tree

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Windows checkouts must not use CRLF on shell scripts — breaks Linux shebang/exec
2+
# (symptom: exec /usr/local/bin/docker-entrypoint.sh: no such file or directory)
3+
*.sh text eol=lf

api/package-lock.json

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

api/package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,18 @@
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",
5858
"p-limit": "^6.2.0",
5959
"php-serialize": "^5.1.3",
6060
"socket.io": "^4.7.5",
6161
"uuid": "^9.0.1",
62-
"winston": "^3.11.0"
62+
"winston": "^3.11.0",
63+
"@emnapi/core": "1.9.1",
64+
"@emnapi/runtime" : "1.9.1",
65+
"@emnapi/wasi-threads": "1.2.0"
6366
},
6467
"devDependencies": {
6568
"@types/cors": "^2.8.17",
@@ -95,7 +98,8 @@
9598
"glob": ">=11.1.0",
9699
"rollup": ">=4.59.0",
97100
"tar": ">=7.5.8",
98-
"@tootallnate/once": ">=3.0.1"
101+
"@tootallnate/once": ">=3.0.1",
102+
"undici": ">=7.24.0"
99103
},
100104
"keywords": []
101105
}

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
}

api/src/utils/market-app.utils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import contentstack from '@contentstack/marketplace-sdk';
1+
import {client} from '@contentstack/marketplace-sdk';
22
import { DEVURLS } from '../constants/index.js';
33

44

55

66

77
export const getAllApps = async ({ organizationUid, authtoken, region }: any) => {
88
try {
9-
const client = contentstack.client({ authtoken, host: DEVURLS?.[region] ?? DEVURLS?.NA });
10-
const data = await client.marketplace(organizationUid).findAllApps();
9+
const contentstackclient = client({ authtoken, host: DEVURLS?.[region] ?? DEVURLS?.NA });
10+
const data = await contentstackclient.marketplace(organizationUid).findAllApps();
1111
return data?.items;
1212
} catch (err) {
1313
console.info("🚀 ~ getAllApps ~ err:", err)
@@ -16,8 +16,8 @@ export const getAllApps = async ({ organizationUid, authtoken, region }: any) =>
1616

1717
export const getAppManifestAndAppConfig = async ({ organizationUid, authtoken, region, manifestUid }: any) => {
1818
try {
19-
const client = contentstack.client({ authtoken, host: DEVURLS?.[region] ?? DEVURLS?.NA });
20-
const data = await client.marketplace(organizationUid).app(manifestUid).fetch();
19+
const contentstackclient = client({ authtoken, host: DEVURLS?.[region] ?? DEVURLS?.NA });
20+
const data = await contentstackclient.marketplace(organizationUid).app(manifestUid).fetch();
2121
return data;
2222
} catch (err: any) {
2323
console.info("🚀 ~ getAppManifestAndAppConfig ~ err:", err)

api/tests/unit/utils/market-app.utils.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ const mockClient = {
55
};
66

77
vi.mock('@contentstack/marketplace-sdk', () => ({
8-
default: {
9-
client: vi.fn(() => mockClient),
10-
},
8+
client: vi.fn(() => mockClient),
119
}));
1210

1311
vi.mock('../../../src/constants/index.js', () => ({
@@ -17,7 +15,7 @@ vi.mock('../../../src/constants/index.js', () => ({
1715
},
1816
}));
1917

20-
import contentstack from '@contentstack/marketplace-sdk';
18+
import { client as marketplaceClient } from '@contentstack/marketplace-sdk';
2119
import {
2220
getAllApps,
2321
getAppManifestAndAppConfig,
@@ -48,7 +46,7 @@ describe('market-app.utils', () => {
4846
});
4947

5048
expect(result).toEqual(mockItems);
51-
expect(contentstack.client).toHaveBeenCalledWith({
49+
expect(marketplaceClient).toHaveBeenCalledWith({
5250
authtoken: 'token-xyz',
5351
host: 'developerhub-api.contentstack.com',
5452
});
@@ -66,7 +64,7 @@ describe('market-app.utils', () => {
6664
region: 'EU',
6765
});
6866

69-
expect(contentstack.client).toHaveBeenCalledWith({
67+
expect(marketplaceClient).toHaveBeenCalledWith({
7068
authtoken: 'token',
7169
host: 'eu-developerhub-api.contentstack.com',
7270
});

0 commit comments

Comments
 (0)