From a8b6bca85d8e0fd3d8003414dcad0d7a25737402 Mon Sep 17 00:00:00 2001 From: shafeeqd959 Date: Fri, 16 Aug 2024 16:09:55 +0530 Subject: [PATCH 1/3] personalize api update for contentype attachment --- .../src/export/experiences.ts | 11 ++++++++--- .../src/import/experiences.ts | 11 +++++++++-- .../src/types/personalization-api-adapter.ts | 13 +++++++++++++ .../src/types/variant-api-adapter.ts | 1 + .../src/utils/adapter-helper.ts | 2 ++ .../src/utils/personalization-api-adapter.ts | 18 +++++++++++++----- 6 files changed, 46 insertions(+), 10 deletions(-) diff --git a/packages/contentstack-variants/src/export/experiences.ts b/packages/contentstack-variants/src/export/experiences.ts index d51e9ae55a..450d16cfa2 100644 --- a/packages/contentstack-variants/src/export/experiences.ts +++ b/packages/contentstack-variants/src/export/experiences.ts @@ -11,6 +11,10 @@ export default class ExportExperiences extends PersonalizationAdapter { config, baseURL: config.modules.personalization.baseURL[config.region.name], headers: { 'X-Project-Uid': config.modules.personalization.project_id, authtoken: config.auth_token }, + cmaConfig: { + baseURL: config.region.cma + `/v3`, + headers: { authtoken: config.auth_token, api_key: config.apiKey }, + }, }; super(Object.assign(config, conf)); this.personalizationConfig = this.config.modules.personalization; @@ -177,7 +181,7 @@ export default class Experiences extends PersonalizationAdapter { return; } const experienceCTsMap = fsUtil.readFile(this.experienceCTsPath, true) as Record; - await Promise.allSettled( + return await Promise.allSettled( Object.entries(this.experiencesUidMapper).map(async ([oldExpUid, newExpUid]) => { if (experienceCTsMap[oldExpUid]?.length) { // Filter content types that were created @@ -185,8 +189,11 @@ export default class Experiences extends PersonalizationAdapter { this.createdCTs.includes(ct), ); if (updatedContentTypes?.length) { + const { variant_groups: [variantGroup] = [] } = + (await this.getVariantGroup({ experienceUid: newExpUid })) || {}; + variantGroup.content_types = updatedContentTypes; // Update content types detail in the new experience asynchronously - await this.updateCTsInExperience({ contentTypes: updatedContentTypes }, newExpUid); + return await this.updateVariantGroup(variantGroup); } } }), diff --git a/packages/contentstack-variants/src/types/personalization-api-adapter.ts b/packages/contentstack-variants/src/types/personalization-api-adapter.ts index fc724f82b2..2036511706 100644 --- a/packages/contentstack-variants/src/types/personalization-api-adapter.ts +++ b/packages/contentstack-variants/src/types/personalization-api-adapter.ts @@ -29,6 +29,18 @@ export interface CreateProjectInput { export type GetVariantGroupInput = { experienceUid: string; }; + +export type VariantGroup = { + uid: string; + name: string; + content_types: string[]; + description: string; +} & AnyProperty; + +export type VariantGroupStruct = { + variant_groups: Array; +} & AnyProperty; + export type EventStruct = { _id: string; uid: string; @@ -152,6 +164,7 @@ export type VariantAPIRes = | EventStruct | AudienceStruct | CMSExperienceStruct + | VariantGroupStruct | Error; export interface APIResponse { diff --git a/packages/contentstack-variants/src/types/variant-api-adapter.ts b/packages/contentstack-variants/src/types/variant-api-adapter.ts index e422d11210..bb1ea3ba28 100644 --- a/packages/contentstack-variants/src/types/variant-api-adapter.ts +++ b/packages/contentstack-variants/src/types/variant-api-adapter.ts @@ -12,6 +12,7 @@ export type APIConfig = HttpRequestConfig & { personalizationURL?: string; config: ExportConfig | Record | undefined; baseURL?: string; + cmaConfig?: HttpRequestConfig; }; export interface AdapterConstructor { diff --git a/packages/contentstack-variants/src/utils/adapter-helper.ts b/packages/contentstack-variants/src/utils/adapter-helper.ts index e701d272d1..541048ddc5 100644 --- a/packages/contentstack-variants/src/utils/adapter-helper.ts +++ b/packages/contentstack-variants/src/utils/adapter-helper.ts @@ -8,6 +8,7 @@ export class AdapterHelper implements AdapterHelperInterface implements AdapterHelperInterface extends AdapterHelper impl return this.handleVariantAPIRes(data) as ExperienceStruct; } - async getVariantGroup(input: GetVariantGroupInput): Promise { - const getVariantGroupEndPoint = `/experiences/${input.experienceUid}`; - const data = await this.apiClient.get(getVariantGroupEndPoint); - return this.handleVariantAPIRes(data) as ExperienceStruct; + async getVariantGroup(input: GetVariantGroupInput): Promise { + const getVariantGroupEndPoint = `/variant_groups`; + const data = await this.cmaAPIClient + .queryParams({ experience_uid: input.experienceUid }) + .get(getVariantGroupEndPoint); + return this.handleVariantAPIRes(data) as VariantGroupStruct; } - async updateVariantGroup(input: unknown): Promise {} + async updateVariantGroup(input: VariantGroup): Promise { + const updateVariantGroupEndPoint = `/variant_groups/${input.uid}`; + const data = await this.cmaAPIClient.put(updateVariantGroupEndPoint, input); + return this.handleVariantAPIRes(data) as VariantGroup; + } async getEvents(): Promise { const data = await this.apiClient.get('/events'); From 028920dd2dd959e9361e996dd53d6b0bf5bcd1fb Mon Sep 17 00:00:00 2001 From: shafeeqd959 Date: Fri, 16 Aug 2024 16:13:19 +0530 Subject: [PATCH 2/3] cma config check in adapter --- packages/contentstack-variants/src/utils/adapter-helper.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/contentstack-variants/src/utils/adapter-helper.ts b/packages/contentstack-variants/src/utils/adapter-helper.ts index 541048ddc5..cc3d57b2fd 100644 --- a/packages/contentstack-variants/src/utils/adapter-helper.ts +++ b/packages/contentstack-variants/src/utils/adapter-helper.ts @@ -8,7 +8,7 @@ export class AdapterHelper implements AdapterHelperInterface implements AdapterHelperInterface Date: Mon, 19 Aug 2024 10:53:43 +0530 Subject: [PATCH 3/3] axios upgraded --- package-lock.json | 96 ++++++++++++++----- packages/contentstack-utilities/package.json | 2 +- .../src/utils/personalization-api-adapter.ts | 20 ++-- pnpm-lock.yaml | 16 +++- 4 files changed, 98 insertions(+), 36 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4d78ce0192..a9ca3278da 100644 --- a/package-lock.json +++ b/package-lock.json @@ -440,6 +440,36 @@ "@babel/core": "^7.0.0-0" } }, + "node_modules/@babel/plugin-syntax-class-static-block": { + "version": "7.14.5", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-class-static-block/-/plugin-syntax-class-static-block-7.14.5.tgz", + "integrity": "sha512-b+YyPmr6ldyNnM6sqYeMWE+bgJcJpO6yS4QD7ymxgH34GBPNDM/THBh8iunyvKIZztiwLH4CJZ0RxTk9emgpjw==", + "dev": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.14.5" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-syntax-import-attributes": { + "version": "7.24.7", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-import-attributes/-/plugin-syntax-import-attributes-7.24.7.tgz", + "integrity": "sha512-hbX+lKKeUMGihnK8nvKqmXBInriT3GVjzXKFriV3YC6APGxMbP8RZNFwy91+hocLXq90Mta+HshoB31802bb8A==", + "dev": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.7" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, "node_modules/@babel/plugin-syntax-import-meta": { "version": "7.10.4", "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-import-meta/-/plugin-syntax-import-meta-7.10.4.tgz", @@ -551,6 +581,21 @@ "@babel/core": "^7.0.0-0" } }, + "node_modules/@babel/plugin-syntax-private-property-in-object": { + "version": "7.14.5", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-private-property-in-object/-/plugin-syntax-private-property-in-object-7.14.5.tgz", + "integrity": "sha512-0wVnp9dxJ72ZUJDV27ZfbSj6iHLoytYZmh3rFcxNnvsJF3ktkzLDZPy/mA17HGsaQT3/DQsWYX1f1QGWkCoVUg==", + "dev": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.14.5" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, "node_modules/@babel/plugin-syntax-top-level-await": { "version": "7.14.5", "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-top-level-await/-/plugin-syntax-top-level-await-7.14.5.tgz", @@ -4352,9 +4397,9 @@ } }, "node_modules/aws-sdk": { - "version": "2.1672.0", - "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1672.0.tgz", - "integrity": "sha512-en4uaVWE/wPa9YsF2XAYtKP0hLQ10s93/nWe+SQ8Yox1xrDn1Tr32MMOtSLRXLxPRKcvmI7Yzw7jiQMgs1jqBQ==", + "version": "2.1676.0", + "resolved": "https://registry.npmjs.org/aws-sdk/-/aws-sdk-2.1676.0.tgz", + "integrity": "sha512-Kzg9931GroRG6uLoUEF5Pcp005D1xilgQ8ntH0fKFxiYKGkQqkU/3JkV6k7jNRzouxTypaozzXYVNXsHRgH6JA==", "dev": true, "hasInstallScript": true, "dependencies": { @@ -4383,9 +4428,9 @@ } }, "node_modules/axios": { - "version": "1.7.3", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.3.tgz", - "integrity": "sha512-Ar7ND9pU99eJ9GpoGQKhKf58GpUOgnzuaB7ueNQ5BMi0p+LZ5oaEnfF999fAArcTIBwXTCHAmGcHOZJaWPq9Nw==", + "version": "1.7.4", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.4.tgz", + "integrity": "sha512-DukmaFRnY6AzAALSH4J2M3k6PkaC+MfaAGdEERRWcC9q3/TWQwLpHR8ZRLKTdQ3aBDL64EdluRDjJqKw+BPZEw==", "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", @@ -4470,23 +4515,26 @@ } }, "node_modules/babel-preset-current-node-syntax": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/babel-preset-current-node-syntax/-/babel-preset-current-node-syntax-1.0.1.tgz", - "integrity": "sha512-M7LQ0bxarkxQoN+vz5aJPsLBn77n8QgTFmo8WK0/44auK2xlCXrYcUxHFxgU7qW5Yzw/CjmLRK2uJzaCd7LvqQ==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/babel-preset-current-node-syntax/-/babel-preset-current-node-syntax-1.1.0.tgz", + "integrity": "sha512-ldYss8SbBlWva1bs28q78Ju5Zq1F+8BrqBZZ0VFhLBvhh6lCpC2o3gDJi/5DRLs9FgYZCnmPYIVFU4lRXCkyUw==", "dev": true, "dependencies": { "@babel/plugin-syntax-async-generators": "^7.8.4", "@babel/plugin-syntax-bigint": "^7.8.3", - "@babel/plugin-syntax-class-properties": "^7.8.3", - "@babel/plugin-syntax-import-meta": "^7.8.3", + "@babel/plugin-syntax-class-properties": "^7.12.13", + "@babel/plugin-syntax-class-static-block": "^7.14.5", + "@babel/plugin-syntax-import-attributes": "^7.24.7", + "@babel/plugin-syntax-import-meta": "^7.10.4", "@babel/plugin-syntax-json-strings": "^7.8.3", - "@babel/plugin-syntax-logical-assignment-operators": "^7.8.3", + "@babel/plugin-syntax-logical-assignment-operators": "^7.10.4", "@babel/plugin-syntax-nullish-coalescing-operator": "^7.8.3", - "@babel/plugin-syntax-numeric-separator": "^7.8.3", + "@babel/plugin-syntax-numeric-separator": "^7.10.4", "@babel/plugin-syntax-object-rest-spread": "^7.8.3", "@babel/plugin-syntax-optional-catch-binding": "^7.8.3", "@babel/plugin-syntax-optional-chaining": "^7.8.3", - "@babel/plugin-syntax-top-level-await": "^7.8.3" + "@babel/plugin-syntax-private-property-in-object": "^7.14.5", + "@babel/plugin-syntax-top-level-await": "^7.14.5" }, "peerDependencies": { "@babel/core": "^7.0.0" @@ -6662,9 +6710,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.5.6", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.6.tgz", - "integrity": "sha512-jwXWsM5RPf6j9dPYzaorcBSUg6AiqocPEyMpkchkvntaH9HGfOOMZwxMJjDY/XEs3T5dM7uyH1VhRMkqUU9qVw==", + "version": "1.5.9", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.9.tgz", + "integrity": "sha512-HfkT8ndXR0SEkU8gBQQM3rz035bpE/hxkZ1YIt4KJPEFES68HfIU6LzKukH0H794Lm83WJtkSAMfEToxCs15VA==", "dev": true }, "node_modules/elegant-spinner": { @@ -9721,9 +9769,9 @@ "integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg==" }, "node_modules/ignore": { - "version": "5.3.1", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.1.tgz", - "integrity": "sha512-5Fytz/IraMjqpwfd34ke28PTVMjZjJG2MPn5t7OE4eUCUNf8BAa7b5WUS9/Qvr6mwOQS7Mk6vdsMno5he+T8Xw==", + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", + "integrity": "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==", "engines": { "node": ">= 4" } @@ -22946,9 +22994,9 @@ } }, "node_modules/winston": { - "version": "3.14.1", - "resolved": "https://registry.npmjs.org/winston/-/winston-3.14.1.tgz", - "integrity": "sha512-CJi4Il/msz8HkdDfXOMu+r5Au/oyEjFiOZzbX2d23hRLY0narGjqfE5lFlrT5hfYJhPtM8b85/GNFsxIML/RVA==", + "version": "3.14.2", + "resolved": "https://registry.npmjs.org/winston/-/winston-3.14.2.tgz", + "integrity": "sha512-CO8cdpBB2yqzEf8v895L+GNKYJiEq8eKlHU38af3snQBQ+sdAIUepjMSguOIJC7ICbzm0ZI+Af2If4vIJrtmOg==", "dependencies": { "@colors/colors": "^1.6.0", "@dabh/diagnostics": "^2.0.2", @@ -26679,7 +26727,7 @@ "@contentstack/management": "~1.17.0", "@contentstack/marketplace-sdk": "^1.2.1", "@oclif/core": "^3.26.5", - "axios": "^1.6.4", + "axios": "^1.7.4", "chalk": "^4.0.0", "cli-cursor": "^3.1.0", "cli-table": "^0.3.11", diff --git a/packages/contentstack-utilities/package.json b/packages/contentstack-utilities/package.json index bc98a3f7a9..514b5558c9 100644 --- a/packages/contentstack-utilities/package.json +++ b/packages/contentstack-utilities/package.json @@ -35,7 +35,7 @@ "@contentstack/management": "~1.17.0", "@contentstack/marketplace-sdk": "^1.2.1", "@oclif/core": "^3.26.5", - "axios": "^1.6.4", + "axios": "^1.7.4", "chalk": "^4.0.0", "cli-cursor": "^3.1.0", "cli-table": "^0.3.11", diff --git a/packages/contentstack-variants/src/utils/personalization-api-adapter.ts b/packages/contentstack-variants/src/utils/personalization-api-adapter.ts index 4c672e226b..531b22d698 100644 --- a/packages/contentstack-variants/src/utils/personalization-api-adapter.ts +++ b/packages/contentstack-variants/src/utils/personalization-api-adapter.ts @@ -78,17 +78,21 @@ export class PersonalizationAdapter extends AdapterHelper impl } async getVariantGroup(input: GetVariantGroupInput): Promise { - const getVariantGroupEndPoint = `/variant_groups`; - const data = await this.cmaAPIClient - .queryParams({ experience_uid: input.experienceUid }) - .get(getVariantGroupEndPoint); - return this.handleVariantAPIRes(data) as VariantGroupStruct; + if (this.cmaAPIClient) { + const getVariantGroupEndPoint = `/variant_groups`; + const data = await this.cmaAPIClient + .queryParams({ experience_uid: input.experienceUid }) + .get(getVariantGroupEndPoint); + return this.handleVariantAPIRes(data) as VariantGroupStruct; + } } async updateVariantGroup(input: VariantGroup): Promise { - const updateVariantGroupEndPoint = `/variant_groups/${input.uid}`; - const data = await this.cmaAPIClient.put(updateVariantGroupEndPoint, input); - return this.handleVariantAPIRes(data) as VariantGroup; + if (this.cmaAPIClient) { + const updateVariantGroupEndPoint = `/variant_groups/${input.uid}`; + const data = await this.cmaAPIClient.put(updateVariantGroupEndPoint, input); + return this.handleVariantAPIRes(data) as VariantGroup; + } } async getEvents(): Promise { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 76952779b9..76ee584af1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1057,7 +1057,7 @@ importers: '@types/node': ^14.14.32 '@types/sinon': ^10.0.2 '@types/traverse': ^0.6.34 - axios: ^1.6.4 + axios: ^1.7.4 chai: ^4.3.4 chalk: ^4.0.0 cli-cursor: ^3.1.0 @@ -1098,7 +1098,7 @@ importers: '@contentstack/management': 1.17.0_debug@4.3.6 '@contentstack/marketplace-sdk': 1.2.2_debug@4.3.6 '@oclif/core': 3.27.0 - axios: 1.7.3_debug@4.3.6 + axios: 1.7.4_debug@4.3.6 chalk: 4.1.2 cli-cursor: 3.1.0 cli-table: 0.3.11 @@ -1611,7 +1611,7 @@ packages: /@contentstack/marketplace-sdk/1.2.2_debug@4.3.6: resolution: {integrity: sha512-qJ6VuNcr24zyNnLj8PfKooMRxmE3OqGMkXwfKZbJAhI2SXNn7qDNVdAwYixaOc7WzgJXHiMoH2lDv6yq1fvFtg==} dependencies: - axios: 1.7.3_debug@4.3.6 + axios: 1.7.4_debug@4.3.6 transitivePeerDependencies: - debug dev: false @@ -4726,6 +4726,16 @@ packages: - debug dev: false + /axios/1.7.4_debug@4.3.6: + resolution: {integrity: sha512-DukmaFRnY6AzAALSH4J2M3k6PkaC+MfaAGdEERRWcC9q3/TWQwLpHR8ZRLKTdQ3aBDL64EdluRDjJqKw+BPZEw==} + dependencies: + follow-redirects: 1.15.6_debug@4.3.6 + form-data: 4.0.0 + proxy-from-env: 1.1.0 + transitivePeerDependencies: + - debug + dev: false + /babel-jest/29.7.0_@babel+core@7.25.2: resolution: {integrity: sha512-BrvGY3xZSwEcCzKvKsCi2GgHqDqsYkOP4/by5xCgIwGXQxIEh+8ew3gmrE1y7XRR6LHZIj6yLYnUi/mm2KXKBg==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}