From 5ca4a8d4d95f128fc25ce1aed08c3b941f82aca3 Mon Sep 17 00:00:00 2001 From: "Rahul R." Date: Sun, 13 Oct 2024 13:57:38 +0530 Subject: [PATCH] fix: #8386 added origin into `api_call_log` table --- packages/contracts/src/api-call-log.model.ts | 1 + .../src/api-call-log/api-call-log.entity.ts | 20 +++++++++++++------ .../1728645657957-CreateApiCallLogTable.ts | 14 ++++++------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/packages/contracts/src/api-call-log.model.ts b/packages/contracts/src/api-call-log.model.ts index 0a9b268ad8f..0cae2252f3a 100644 --- a/packages/contracts/src/api-call-log.model.ts +++ b/packages/contracts/src/api-call-log.model.ts @@ -32,4 +32,5 @@ export interface IApiCallLog extends IBasePerTenantAndOrganizationEntityModel, I ipAddress: string; // The IP address of the client making the request. protocol: string; // The protocol used in the request (HTTP, HTTPS). userAgent: string; // User-Agent string of the client making the request (could be a browser, desktop app, Postman, etc.). + origin: string; // Origin from where the request was initiated (web, mobile, desktop, etc.). } diff --git a/packages/core/src/api-call-log/api-call-log.entity.ts b/packages/core/src/api-call-log/api-call-log.entity.ts index 4317944bf4d..964bf65f717 100644 --- a/packages/core/src/api-call-log/api-call-log.entity.ts +++ b/packages/core/src/api-call-log/api-call-log.entity.ts @@ -104,21 +104,29 @@ export class ApiCallLog extends TenantOrganizationBaseEntity implements IApiCall /** * The protocol used in the request (HTTP, HTTPS) */ - @ApiProperty({ type: () => String }) - @IsNotEmpty() + @ApiPropertyOptional({ type: () => String }) + @IsOptional() @ColumnIndex() - @MultiORMColumn() + @MultiORMColumn({ nullable: true }) protocol: string; /** * User-Agent string of the client making the request. * This could be a browser, desktop app, Postman, or any other API client. */ - @ApiProperty({ type: () => String }) - @IsNotEmpty() - @MultiORMColumn() + @ApiPropertyOptional({ type: () => String }) + @IsOptional() + @MultiORMColumn({ nullable: true }) userAgent: string; + /** + * Origin from where the request was initiated (web, mobile, desktop, etc.). + */ + @ApiPropertyOptional({ type: () => String }) + @IsOptional() + @MultiORMColumn({ nullable: true }) + origin: string; // Added column to track request origin + /* |-------------------------------------------------------------------------- | @ManyToOne diff --git a/packages/core/src/database/migrations/1728645657957-CreateApiCallLogTable.ts b/packages/core/src/database/migrations/1728645657957-CreateApiCallLogTable.ts index e3004b59778..f55eb92dfa7 100644 --- a/packages/core/src/database/migrations/1728645657957-CreateApiCallLogTable.ts +++ b/packages/core/src/database/migrations/1728645657957-CreateApiCallLogTable.ts @@ -58,7 +58,7 @@ export class CreateApiCallLogTable1728645657957 implements MigrationInterface { */ public async postgresUpQueryRunner(queryRunner: QueryRunner): Promise { await queryRunner.query( - `CREATE TABLE "api_call_log" ("deletedAt" TIMESTAMP, "id" uuid NOT NULL DEFAULT gen_random_uuid(), "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "isActive" boolean DEFAULT true, "isArchived" boolean DEFAULT false, "archivedAt" TIMESTAMP, "tenantId" uuid, "organizationId" uuid, "correlationId" character varying NOT NULL, "url" character varying NOT NULL, "method" integer NOT NULL, "requestHeaders" jsonb NOT NULL, "requestBody" jsonb NOT NULL, "responseBody" jsonb NOT NULL, "statusCode" integer NOT NULL, "requestTime" TIMESTAMP NOT NULL, "responseTime" TIMESTAMP NOT NULL, "ipAddress" character varying, "protocol" character varying NOT NULL, "userAgent" character varying NOT NULL, "userId" uuid, CONSTRAINT "PK_ba8bfaffbb35aff7026eecae2a7" PRIMARY KEY ("id"))` + `CREATE TABLE "api_call_log" ("deletedAt" TIMESTAMP, "id" uuid NOT NULL DEFAULT gen_random_uuid(), "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "isActive" boolean DEFAULT true, "isArchived" boolean DEFAULT false, "archivedAt" TIMESTAMP, "tenantId" uuid, "organizationId" uuid, "correlationId" character varying NOT NULL, "url" character varying NOT NULL, "method" integer NOT NULL, "requestHeaders" jsonb NOT NULL, "requestBody" jsonb NOT NULL, "responseBody" jsonb NOT NULL, "statusCode" integer NOT NULL, "requestTime" TIMESTAMP NOT NULL, "responseTime" TIMESTAMP NOT NULL, "ipAddress" character varying, "protocol" character varying, "userAgent" character varying, "origin" character varying, "userId" uuid, CONSTRAINT "PK_ba8bfaffbb35aff7026eecae2a7" PRIMARY KEY ("id"))` ); await queryRunner.query(`CREATE INDEX "IDX_f3505a1756b04b59626d1bd836" ON "api_call_log" ("isActive") `); await queryRunner.query(`CREATE INDEX "IDX_85c20063cd74c766533fd08389" ON "api_call_log" ("isArchived") `); @@ -116,7 +116,7 @@ export class CreateApiCallLogTable1728645657957 implements MigrationInterface { */ public async sqliteUpQueryRunner(queryRunner: QueryRunner): Promise { await queryRunner.query( - `CREATE TABLE "api_call_log" ("deletedAt" datetime, "id" varchar PRIMARY KEY NOT NULL, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')), "isActive" boolean DEFAULT (1), "isArchived" boolean DEFAULT (0), "archivedAt" datetime, "tenantId" varchar, "organizationId" varchar, "correlationId" varchar NOT NULL, "url" varchar NOT NULL, "method" integer NOT NULL, "requestHeaders" text NOT NULL, "requestBody" text NOT NULL, "responseBody" text NOT NULL, "statusCode" integer NOT NULL, "requestTime" datetime NOT NULL, "responseTime" datetime NOT NULL, "ipAddress" varchar, "protocol" varchar NOT NULL, "userAgent" varchar NOT NULL, "userId" varchar)` + `CREATE TABLE "api_call_log" ("deletedAt" datetime, "id" varchar PRIMARY KEY NOT NULL, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')), "isActive" boolean DEFAULT (1), "isArchived" boolean DEFAULT (0), "archivedAt" datetime, "tenantId" varchar, "organizationId" varchar, "correlationId" varchar NOT NULL, "url" varchar NOT NULL, "method" integer NOT NULL, "requestHeaders" text NOT NULL, "requestBody" text NOT NULL, "responseBody" text NOT NULL, "statusCode" integer NOT NULL, "requestTime" datetime NOT NULL, "responseTime" datetime NOT NULL, "ipAddress" varchar, "protocol" varchar, "userAgent" varchar, "origin" varchar, "userId" varchar)` ); await queryRunner.query(`CREATE INDEX "IDX_f3505a1756b04b59626d1bd836" ON "api_call_log" ("isActive") `); await queryRunner.query(`CREATE INDEX "IDX_85c20063cd74c766533fd08389" ON "api_call_log" ("isArchived") `); @@ -145,10 +145,10 @@ export class CreateApiCallLogTable1728645657957 implements MigrationInterface { await queryRunner.query(`DROP INDEX "IDX_964d6a55608f67f7d92e9827db"`); await queryRunner.query(`DROP INDEX "IDX_ada33b1685138be7798aea280b"`); await queryRunner.query( - `CREATE TABLE "temporary_api_call_log" ("deletedAt" datetime, "id" varchar PRIMARY KEY NOT NULL, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')), "isActive" boolean DEFAULT (1), "isArchived" boolean DEFAULT (0), "archivedAt" datetime, "tenantId" varchar, "organizationId" varchar, "correlationId" varchar NOT NULL, "url" varchar NOT NULL, "method" integer NOT NULL, "requestHeaders" text NOT NULL, "requestBody" text NOT NULL, "responseBody" text NOT NULL, "statusCode" integer NOT NULL, "requestTime" datetime NOT NULL, "responseTime" datetime NOT NULL, "ipAddress" varchar, "protocol" varchar NOT NULL, "userAgent" varchar NOT NULL, "userId" varchar, CONSTRAINT "FK_94c4d067f73d90faaad8c2d3dbd" FOREIGN KEY ("tenantId") REFERENCES "tenant" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_89292145eeceb7ff32dac0de83b" FOREIGN KEY ("organizationId") REFERENCES "organization" ("id") ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT "FK_ada33b1685138be7798aea280b2" FOREIGN KEY ("userId") REFERENCES "user" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)` + `CREATE TABLE "temporary_api_call_log" ("deletedAt" datetime, "id" varchar PRIMARY KEY NOT NULL, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')), "isActive" boolean DEFAULT (1), "isArchived" boolean DEFAULT (0), "archivedAt" datetime, "tenantId" varchar, "organizationId" varchar, "correlationId" varchar NOT NULL, "url" varchar NOT NULL, "method" integer NOT NULL, "requestHeaders" text NOT NULL, "requestBody" text NOT NULL, "responseBody" text NOT NULL, "statusCode" integer NOT NULL, "requestTime" datetime NOT NULL, "responseTime" datetime NOT NULL, "ipAddress" varchar, "protocol" varchar, "userAgent" varchar, "origin" varchar, "userId" varchar, CONSTRAINT "FK_94c4d067f73d90faaad8c2d3dbd" FOREIGN KEY ("tenantId") REFERENCES "tenant" ("id") ON DELETE CASCADE ON UPDATE NO ACTION, CONSTRAINT "FK_89292145eeceb7ff32dac0de83b" FOREIGN KEY ("organizationId") REFERENCES "organization" ("id") ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT "FK_ada33b1685138be7798aea280b2" FOREIGN KEY ("userId") REFERENCES "user" ("id") ON DELETE CASCADE ON UPDATE NO ACTION)` ); await queryRunner.query( - `INSERT INTO "temporary_api_call_log"("deletedAt", "id", "createdAt", "updatedAt", "isActive", "isArchived", "archivedAt", "tenantId", "organizationId", "correlationId", "url", "method", "requestHeaders", "requestBody", "responseBody", "statusCode", "requestTime", "responseTime", "ipAddress", "protocol", "userAgent", "userId") SELECT "deletedAt", "id", "createdAt", "updatedAt", "isActive", "isArchived", "archivedAt", "tenantId", "organizationId", "correlationId", "url", "method", "requestHeaders", "requestBody", "responseBody", "statusCode", "requestTime", "responseTime", "ipAddress", "protocol", "userAgent", "userId" FROM "api_call_log"` + `INSERT INTO "temporary_api_call_log"("deletedAt", "id", "createdAt", "updatedAt", "isActive", "isArchived", "archivedAt", "tenantId", "organizationId", "correlationId", "url", "method", "requestHeaders", "requestBody", "responseBody", "statusCode", "requestTime", "responseTime", "ipAddress", "protocol", "userAgent", "origin", "userId") SELECT "deletedAt", "id", "createdAt", "updatedAt", "isActive", "isArchived", "archivedAt", "tenantId", "organizationId", "correlationId", "url", "method", "requestHeaders", "requestBody", "responseBody", "statusCode", "requestTime", "responseTime", "ipAddress", "protocol", "userAgent", "origin", "userId" FROM "api_call_log"` ); await queryRunner.query(`DROP TABLE "api_call_log"`); await queryRunner.query(`ALTER TABLE "temporary_api_call_log" RENAME TO "api_call_log"`); @@ -188,10 +188,10 @@ export class CreateApiCallLogTable1728645657957 implements MigrationInterface { await queryRunner.query(`DROP INDEX "IDX_f3505a1756b04b59626d1bd836"`); await queryRunner.query(`ALTER TABLE "api_call_log" RENAME TO "temporary_api_call_log"`); await queryRunner.query( - `CREATE TABLE "api_call_log" ("deletedAt" datetime, "id" varchar PRIMARY KEY NOT NULL, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')), "isActive" boolean DEFAULT (1), "isArchived" boolean DEFAULT (0), "archivedAt" datetime, "tenantId" varchar, "organizationId" varchar, "correlationId" varchar NOT NULL, "url" varchar NOT NULL, "method" integer NOT NULL, "requestHeaders" text NOT NULL, "requestBody" text NOT NULL, "responseBody" text NOT NULL, "statusCode" integer NOT NULL, "requestTime" datetime NOT NULL, "responseTime" datetime NOT NULL, "ipAddress" varchar, "protocol" varchar NOT NULL, "userAgent" varchar NOT NULL, "userId" varchar)` + `CREATE TABLE "api_call_log" ("deletedAt" datetime, "id" varchar PRIMARY KEY NOT NULL, "createdAt" datetime NOT NULL DEFAULT (datetime('now')), "updatedAt" datetime NOT NULL DEFAULT (datetime('now')), "isActive" boolean DEFAULT (1), "isArchived" boolean DEFAULT (0), "archivedAt" datetime, "tenantId" varchar, "organizationId" varchar, "correlationId" varchar NOT NULL, "url" varchar NOT NULL, "method" integer NOT NULL, "requestHeaders" text NOT NULL, "requestBody" text NOT NULL, "responseBody" text NOT NULL, "statusCode" integer NOT NULL, "requestTime" datetime NOT NULL, "responseTime" datetime NOT NULL, "ipAddress" varchar, "protocol" varchar, "userAgent" varchar, "origin" varchar, "userId" varchar)` ); await queryRunner.query( - `INSERT INTO "api_call_log"("deletedAt", "id", "createdAt", "updatedAt", "isActive", "isArchived", "archivedAt", "tenantId", "organizationId", "correlationId", "url", "method", "requestHeaders", "requestBody", "responseBody", "statusCode", "requestTime", "responseTime", "ipAddress", "protocol", "userAgent", "userId") SELECT "deletedAt", "id", "createdAt", "updatedAt", "isActive", "isArchived", "archivedAt", "tenantId", "organizationId", "correlationId", "url", "method", "requestHeaders", "requestBody", "responseBody", "statusCode", "requestTime", "responseTime", "ipAddress", "protocol", "userAgent", "userId" FROM "temporary_api_call_log"` + `INSERT INTO "api_call_log"("deletedAt", "id", "createdAt", "updatedAt", "isActive", "isArchived", "archivedAt", "tenantId", "organizationId", "correlationId", "url", "method", "requestHeaders", "requestBody", "responseBody", "statusCode", "requestTime", "responseTime", "ipAddress", "protocol", "userAgent", "origin", "userId") SELECT "deletedAt", "id", "createdAt", "updatedAt", "isActive", "isArchived", "archivedAt", "tenantId", "organizationId", "correlationId", "url", "method", "requestHeaders", "requestBody", "responseBody", "statusCode", "requestTime", "responseTime", "ipAddress", "protocol", "userAgent", "origin", "userId" FROM "temporary_api_call_log"` ); await queryRunner.query(`DROP TABLE "temporary_api_call_log"`); await queryRunner.query(`CREATE INDEX "IDX_ada33b1685138be7798aea280b" ON "api_call_log" ("userId") `); @@ -230,7 +230,7 @@ export class CreateApiCallLogTable1728645657957 implements MigrationInterface { */ public async mysqlUpQueryRunner(queryRunner: QueryRunner): Promise { await queryRunner.query( - `CREATE TABLE \`api_call_log\` (\`deletedAt\` datetime(6) NULL, \`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), \`updatedAt\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`isActive\` tinyint NULL DEFAULT 1, \`isArchived\` tinyint NULL DEFAULT 0, \`archivedAt\` datetime NULL, \`tenantId\` varchar(255) NULL, \`organizationId\` varchar(255) NULL, \`correlationId\` varchar(255) NOT NULL, \`url\` varchar(255) NOT NULL, \`method\` int NOT NULL, \`requestHeaders\` json NOT NULL, \`requestBody\` json NOT NULL, \`responseBody\` json NOT NULL, \`statusCode\` int NOT NULL, \`requestTime\` datetime NOT NULL, \`responseTime\` datetime NOT NULL, \`ipAddress\` varchar(255) NULL, \`protocol\` varchar(255) NOT NULL, \`userAgent\` varchar(255) NOT NULL, \`userId\` varchar(255) NULL, INDEX \`IDX_f3505a1756b04b59626d1bd836\` (\`isActive\`), INDEX \`IDX_85c20063cd74c766533fd08389\` (\`isArchived\`), INDEX \`IDX_94c4d067f73d90faaad8c2d3db\` (\`tenantId\`), INDEX \`IDX_89292145eeceb7ff32dac0de83\` (\`organizationId\`), INDEX \`IDX_c74a2db6a95bb3a5b788e23a50\` (\`correlationId\`), INDEX \`IDX_b484d5942747f0c19372ae8fcd\` (\`url\`), INDEX \`IDX_0a62fc4546d596f9e9ce305ecb\` (\`method\`), INDEX \`IDX_5820fe8a6385bfc0338c49a508\` (\`statusCode\`), INDEX \`IDX_1d6cb060eba156d1e50f7ea4a0\` (\`requestTime\`), INDEX \`IDX_66f2fd42fa8f00e11d6960cb39\` (\`responseTime\`), INDEX \`IDX_085b00c43479478866d7a27ca9\` (\`ipAddress\`), INDEX \`IDX_964d6a55608f67f7d92e9827db\` (\`protocol\`), INDEX \`IDX_ada33b1685138be7798aea280b\` (\`userId\`), PRIMARY KEY (\`id\`)) ENGINE=InnoDB` + `CREATE TABLE \`api_call_log\` (\`deletedAt\` datetime(6) NULL, \`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), \`updatedAt\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`isActive\` tinyint NULL DEFAULT 1, \`isArchived\` tinyint NULL DEFAULT 0, \`archivedAt\` datetime NULL, \`tenantId\` varchar(255) NULL, \`organizationId\` varchar(255) NULL, \`correlationId\` varchar(255) NOT NULL, \`url\` varchar(255) NOT NULL, \`method\` int NOT NULL, \`requestHeaders\` json NOT NULL, \`requestBody\` json NOT NULL, \`responseBody\` json NOT NULL, \`statusCode\` int NOT NULL, \`requestTime\` datetime NOT NULL, \`responseTime\` datetime NOT NULL, \`ipAddress\` varchar(255) NULL, \`protocol\` varchar(255) NULL, \`userAgent\` varchar(255) NULL, \`origin\` varchar(255) NULL, \`userId\` varchar(255) NULL, INDEX \`IDX_f3505a1756b04b59626d1bd836\` (\`isActive\`), INDEX \`IDX_85c20063cd74c766533fd08389\` (\`isArchived\`), INDEX \`IDX_94c4d067f73d90faaad8c2d3db\` (\`tenantId\`), INDEX \`IDX_89292145eeceb7ff32dac0de83\` (\`organizationId\`), INDEX \`IDX_c74a2db6a95bb3a5b788e23a50\` (\`correlationId\`), INDEX \`IDX_b484d5942747f0c19372ae8fcd\` (\`url\`), INDEX \`IDX_0a62fc4546d596f9e9ce305ecb\` (\`method\`), INDEX \`IDX_5820fe8a6385bfc0338c49a508\` (\`statusCode\`), INDEX \`IDX_1d6cb060eba156d1e50f7ea4a0\` (\`requestTime\`), INDEX \`IDX_66f2fd42fa8f00e11d6960cb39\` (\`responseTime\`), INDEX \`IDX_085b00c43479478866d7a27ca9\` (\`ipAddress\`), INDEX \`IDX_964d6a55608f67f7d92e9827db\` (\`protocol\`), INDEX \`IDX_ada33b1685138be7798aea280b\` (\`userId\`), PRIMARY KEY (\`id\`)) ENGINE=InnoDB` ); await queryRunner.query( `ALTER TABLE \`api_call_log\` ADD CONSTRAINT \`FK_94c4d067f73d90faaad8c2d3dbd\` FOREIGN KEY (\`tenantId\`) REFERENCES \`tenant\`(\`id\`) ON DELETE CASCADE ON UPDATE NO ACTION`