Skip to content

Commit

Permalink
Merge branch 'main' into issue-31223-add-telemetry-experiments
Browse files Browse the repository at this point in the history
  • Loading branch information
jdotcms authored Feb 26, 2025
2 parents 3a6b19a + 7e1c5d1 commit c3bb348
Show file tree
Hide file tree
Showing 43 changed files with 1,390 additions and 256 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/legacy-release_maven-release-process.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,6 @@ jobs:
with:
path: ${{ env.DOCKER_BUILD_CONTEXT }}/context
key: docker-context-${{ steps.set-common-vars.outputs.date }}-${{ github.run_id }}
restore-keys: |
docker-context-${{ steps.set-common-vars.outputs.date }}
if: success()

- name: Create Release
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe('DotHttpErrorManagerService', () => {
});

it('should handle 401 error when user is logout and redirect to login', () => {
loginService.auth.user = null;
loginService.auth.user = undefined as any;
jest.spyOn(dotDialogService, 'alert');
jest.spyOn(dotRouterService, 'goToLogin');

Expand Down Expand Up @@ -166,7 +166,7 @@ describe('DotHttpErrorManagerService', () => {
'error-key': 'dotcms.api.error.license.required'
});

const responseView: HttpErrorResponse = mockResponseView(403, null, headers);
const responseView: HttpErrorResponse = mockResponseView(403, undefined, headers);

service.handle(responseView).subscribe((res) => {
result = res;
Expand All @@ -186,7 +186,7 @@ describe('DotHttpErrorManagerService', () => {
it('should handle 400 error on message', () => {
jest.spyOn(dotDialogService, 'alert');

const responseView: HttpErrorResponse = mockResponseView(400, null, null, {
const responseView: HttpErrorResponse = mockResponseView(400, undefined, undefined, {
message: 'Error'
});

Expand All @@ -210,7 +210,7 @@ describe('DotHttpErrorManagerService', () => {
const CUSTOM_HEADER = 'Custom Header';
const SERVER_MESSAGE = 'Server Error';

const responseView: HttpErrorResponse = mockResponseView(400, null, null, {
const responseView: HttpErrorResponse = mockResponseView(400, undefined, undefined, {
message: SERVER_MESSAGE,
header: CUSTOM_HEADER
});
Expand All @@ -233,7 +233,7 @@ describe('DotHttpErrorManagerService', () => {
it('should handle 400 error on errors[0]', () => {
jest.spyOn(dotDialogService, 'alert');

const responseView: HttpErrorResponse = mockResponseView(400, null, null, [
const responseView: HttpErrorResponse = mockResponseView(400, undefined, undefined, [
{ message: 'Server Error' }
]);

Expand All @@ -255,7 +255,7 @@ describe('DotHttpErrorManagerService', () => {
it('should handle 400 error on error.errors[0]', () => {
jest.spyOn(dotDialogService, 'alert');

const responseView: HttpErrorResponse = mockResponseView(400, null, null, {
const responseView: HttpErrorResponse = mockResponseView(400, undefined, undefined, {
errors: [{ message: 'Server Error' }]
});

Expand All @@ -277,7 +277,7 @@ describe('DotHttpErrorManagerService', () => {
it('should handle 400 error on error.error', () => {
jest.spyOn(dotDialogService, 'alert');

const responseView: HttpErrorResponse = mockResponseView(400, null, null, {
const responseView: HttpErrorResponse = mockResponseView(400, undefined, undefined, {
error: 'Server Error'
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,97 @@ export class DotHttpErrorManagerService {
return false;
}

/**
* Extracts a readable error message from an HttpErrorResponse
*
* @param response The HttpErrorResponse to extract the message from
* @returns A string containing the error message or empty string if no message found
*/
private getErrorMessage(response?: HttpErrorResponse): string {
let msg: string;
if (Array.isArray(response?.['error']) || Array.isArray(response?.error?.errors)) {
msg = response.error[0]?.message || response.error?.errors[0]?.message;
} else {
const error = response?.['error'];
msg = error?.message || error?.error;
if (!response) {
return '';
}

const { error } = response;
let errorMessage = '';

// Handle array of errors
if (Array.isArray(error) && error.length > 0) {
errorMessage = this.extractMessageFromErrorObject(error[0]);
}
// Handle error object with nested errors array
else if (error?.errors && Array.isArray(error.errors) && error.errors.length > 0) {
errorMessage = this.extractMessageFromErrorObject(error.errors[0]);
}
// Handle direct error object
else if (error && typeof error === 'object') {
errorMessage = this.extractMessageFromErrorObject(error);
}
// Handle string error
else if (error && typeof error === 'string') {
errorMessage = error;
}

// Try to get localized message if it's a message key
const localizedMessage = this.dotMessageService.get(errorMessage);

return localizedMessage !== errorMessage ? localizedMessage : errorMessage;
}

/**
* Extracts message from an error object and trims it if it contains a colon
*
* @param errorObj The error object to extract message from
* @returns The extracted message or empty string
*/
private extractMessageFromErrorObject(errorObj: unknown): string {
if (!errorObj) {
return '';
}

return msg;
// Handle string directly
if (typeof errorObj === 'string') {
return this.formatErrorMessage(errorObj);
}

// Handle error object
if (typeof errorObj === 'object' && errorObj !== null) {
const errorRecord = errorObj as Record<string, unknown>;

// Try to extract message from common error properties in priority order
const message =
this.getStringProperty(errorRecord, 'message') ||
this.getStringProperty(errorRecord, 'error') ||
this.getStringProperty(errorRecord, 'detail') ||
this.getStringProperty(errorRecord, 'description') ||
'';

return this.formatErrorMessage(message);
}

return '';
}

/**
* Safely extracts a string property from an object
*
* @param obj The object to extract from
* @param prop The property name to extract
* @returns The string value or empty string
*/
private getStringProperty(obj: Record<string, unknown>, prop: string): string {
const value = obj[prop];

return typeof value === 'string' ? value : '';
}

/**
* Formats an error message by trimming at first colon if present
*
* @param message The message to format
* @returns The formatted message
*/
private formatErrorMessage(message: string): string {
return message.includes(':') ? message.substring(0, message.indexOf(':')) : message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,15 @@ export function withEditor() {
};
}),
$iframeURL: computed<string | InstanceType<typeof String>>(() => {
const sanitizedURL = sanitizeURL(store.pageParams().url);
/*
Here we need to import pageAPIResponse() to create the computed dependency and have it updated every time a response is received from the PageAPI.
This should change in future UVE improvements.
The url should not depend on the PageAPI response since it does not change (In traditional).
In the future we should have a function that updates the content, independent of the url.
More info: https://github.com/dotCMS/core/issues/31475
*/
const vanityURL = store.pageAPIResponse().vanityUrl?.url;
const sanitizedURL = sanitizeURL(vanityURL ?? store.pageParams().url);

const url = buildIframeURL({
url: sanitizedURL,
Expand Down
2 changes: 1 addition & 1 deletion core-web/libs/sdk/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dotcms/client",
"version": "0.0.1-alpha.38",
"version": "0.0.1-beta.2",
"description": "Official JavaScript library for interacting with DotCMS REST APIs.",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion core-web/libs/sdk/experiments/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dotcms/experiments",
"version": "0.0.1-alpha.38",
"version": "0.0.1-beta.2",
"description": "Official JavaScript library to use Experiments with DotCMS.",
"repository": {
"type": "git",
Expand Down
3 changes: 2 additions & 1 deletion core-web/libs/sdk/experiments/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"allowJs": false,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true
"strict": true,
"moduleResolution": "bundler"
},
"files": [],
"include": ["src"],
Expand Down
13 changes: 12 additions & 1 deletion core-web/libs/sdk/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dotcms/react",
"version": "0.0.1-alpha.38",
"version": "0.0.1-beta-2",
"peerDependencies": {
"react": ">=18",
"react-dom": ">=18",
Expand All @@ -22,6 +22,17 @@
"React",
"Components"
],
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts",
"./next": "./src/next.ts"
},
"typesVersions": {
"*": {
".": ["./src/index.d.ts"],
"next": ["./src/next.d.ts"]
}
},
"author": "dotcms <[email protected]>",
"license": "MIT",
"bugs": {
Expand Down
6 changes: 4 additions & 2 deletions core-web/libs/sdk/react/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@
"executor": "@nx/rollup:rollup",
"outputs": ["{options.outputPath}"],
"options": {
"main": "libs/sdk/react/src/index.ts",
"additionalEntryPoints": ["libs/sdk/react/src/next.ts"],
"generateExportsField": true,
"outputPath": "dist/libs/sdk/react",
"tsConfig": "libs/sdk/react/tsconfig.lib.json",
"project": "libs/sdk/react/package.json",
"entryFile": "libs/sdk/react/src/index.ts",
"additionalEntryPoints": ["libs/sdk/react/src/next.ts"],
"external": ["react/jsx-runtime"],
"rollupConfig": "@nrwl/react/plugins/bundle-rollup",
"compiler": "babel",
"extractCss": false,
"format": ["esm"],
"extractCss": false,
"assets": [
{
"glob": "libs/sdk/react/README.md",
Expand Down
15 changes: 13 additions & 2 deletions core-web/libs/sdk/uve/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dotcms/uve",
"version": "0.0.1",
"version": "0.0.1-beta.2",
"description": "Official JavaScript library for interacting with Universal Visual Editor (UVE)",
"repository": {
"type": "git",
Expand All @@ -13,10 +13,21 @@
"UVE",
"Universal Visual Editor"
],
"exports": {
"./package.json": "./package.json",
".": "./src/index.ts",
"./types": "./src/types.ts"
},
"typesVersions": {
"*": {
".": ["./src/index.d.ts"],
"types": ["./src/types.d.ts"]
}
},
"author": "dotcms <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/dotCMS/core/issues"
},
"homepage": "https://github.com/dotCMS/core/tree/main/core-web/libs/sdk/client/README.md"
"homepage": "https://github.com/dotCMS/core/tree/main/core-web/libs/sdk/uve/README.md"
}
15 changes: 9 additions & 6 deletions core-web/libs/sdk/uve/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@
"executor": "@nx/rollup:rollup",
"outputs": ["{options.outputPath}"],
"options": {
"format": ["esm", "cjs"],
"compiler": "tsc",
"main": "libs/sdk/uve/src/index.ts",
"additionalEntryPoints": ["libs/sdk/uve/src/types.ts"],
"generateExportsField": true,
"assets": [{ "input": "libs/sdk/uve", "output": ".", "glob": "*.md" }],
"outputPath": "dist/libs/sdk/uve",
"main": "libs/sdk/uve/src/public/index.ts",
"additionalEntryPoints": ["libs/sdk/uve/src/public/types.ts"],
"tsConfig": "libs/sdk/uve/tsconfig.lib.json"
"tsConfig": "libs/sdk/uve/tsconfig.lib.json",
"project": "libs/sdk/uve/package.json",
"entryFile": "libs/sdk/uve/src/index.ts",
"compiler": "babel",
"format": ["esm", "cjs"],
"extractCss": false,
"assets": [{ "input": "libs/sdk/uve", "output": ".", "glob": "*.md" }]
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions core-web/libs/sdk/uve/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { getUVEState } from './lib/utils';

export { getUVEState };
3 changes: 0 additions & 3 deletions core-web/libs/sdk/uve/src/public/index.ts

This file was deleted.

3 changes: 0 additions & 3 deletions core-web/libs/sdk/uve/src/public/types.ts

This file was deleted.

3 changes: 3 additions & 0 deletions core-web/libs/sdk/uve/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { UVE_MODE, UVEState } from './lib/types';

export { UVE_MODE, UVEState };
4 changes: 2 additions & 2 deletions core-web/tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
"@dotcms/utils": ["libs/utils/src"],
"@dotcms/utils-testing": ["libs/utils-testing/src/index.ts"],
"@dotcms/utils/*": ["libs/utils/src/*"],
"@dotcms/uve": ["libs/sdk/uve/src/public/index.ts"],
"@dotcms/uve/types": ["libs/sdk/uve/src/public/types.ts"],
"@dotcms/uve": ["libs/sdk/uve/src/index.ts"],
"@dotcms/uve/types": ["libs/sdk/uve/src/types.ts"],
"@models/*": ["apps/dotcms-ui/src/app/shared/models/*"],
"@pipes/*": ["apps/dotcms-ui/src/app/view/pipes/*"],
"@portlets/*": ["apps/dotcms-ui/src/app/portlets/*"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ CREATE TABLE IF NOT EXISTS clickhouse_test_db.events
_timestamp DateTime,
api_key String,
cluster_id String,
customer_name String,
customer_category String,
environment_name String,
environment_version String,
customer_id String,
doc_encoding String,
doc_host String,
Expand Down Expand Up @@ -110,3 +114,9 @@ ALTER TABLE clickhouse_test_db.events DROP COLUMN IF EXISTS object_detail_page_u
ALTER TABLE clickhouse_test_db.events DROP COLUMN IF EXISTS object_url;
ALTER TABLE clickhouse_test_db.events DROP COLUMN IF EXISTS object_forward_to;
ALTER TABLE clickhouse_test_db.events DROP COLUMN IF EXISTS comefromvanityurl;


ALTER TABLE clickhouse_test_db.events ADD COLUMN IF NOT EXISTS customer_name String;
ALTER TABLE clickhouse_test_db.events ADD COLUMN IF NOT EXISTS customer_category String;
ALTER TABLE clickhouse_test_db.events ADD COLUMN IF NOT EXISTS environment_name String;
ALTER TABLE clickhouse_test_db.events ADD COLUMN IF NOT EXISTS environment_version String;
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public AnalyticsAPIImpl() {

@Override
public void notify(final SystemTableUpdatedKeyEvent event) {
Logger.info(this, String.format("Received event with key [%s]", event.getKey()));
if (event.getKey().contains(ANALYTICS_IDP_URL_KEY)) {
analyticsIdpUrl.set(resolveAnalyticsIdpUrl());
} else if (event.getKey().contains(ANALYTICS_ACCESS_TOKEN_RENEW_TIMEOUT_KEY)) {
Expand Down Expand Up @@ -436,5 +437,4 @@ private CircuitBreakerUrl.Response<AnalyticsKey> requestAnalyticsKey(final Analy
private Map<String, String> analyticsKeyHeaders(final AccessToken accessToken) throws AnalyticsException {
return CircuitBreakerUrl.authHeaders(AnalyticsHelper.get().formatBearer(accessToken));
}

}
Loading

0 comments on commit c3bb348

Please sign in to comment.