@contember/engine-http 2.2.0-alpha.18 → 2.2.0-alpha.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/development/index.cjs +0 -1
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +1 -2
- package/dist/development/src/application/application.cjs +8 -9
- package/dist/development/src/application/application.cjs.map +1 -1
- package/dist/development/src/application/application.js +8 -9
- package/dist/development/src/application/application.js.map +1 -1
- package/dist/development/src/application/compression.cjs +99 -0
- package/dist/development/src/application/compression.cjs.map +1 -0
- package/dist/development/src/application/compression.js +82 -0
- package/dist/development/src/application/compression.js.map +1 -0
- package/dist/development/src/application/cors.cjs +52 -0
- package/dist/development/src/application/cors.cjs.map +1 -0
- package/dist/development/src/application/cors.js +52 -0
- package/dist/development/src/application/cors.js.map +1 -0
- package/dist/development/src/application/requestBody.cjs +242 -0
- package/dist/development/src/application/requestBody.cjs.map +1 -0
- package/dist/development/src/application/requestBody.js +242 -0
- package/dist/development/src/application/requestBody.js.map +1 -0
- package/dist/development/src/config/configSchema.cjs +8 -1
- package/dist/development/src/config/configSchema.cjs.map +1 -1
- package/dist/development/src/config/configSchema.js +8 -1
- package/dist/development/src/config/configSchema.js.map +1 -1
- package/dist/development/src/graphql/execution.cjs +3 -9
- package/dist/development/src/graphql/execution.cjs.map +1 -1
- package/dist/development/src/graphql/execution.js +3 -9
- package/dist/development/src/graphql/execution.js.map +1 -1
- package/dist/development/src/project/ProjectContainer.cjs +1 -1
- package/dist/development/src/project/ProjectContainer.js +1 -1
- package/dist/development/src/projectGroup/ProjectGroupContainer.cjs +1 -1
- package/dist/development/src/projectGroup/ProjectGroupContainer.js +1 -1
- package/dist/development/src/providers.cjs +2 -2
- package/dist/development/src/providers.cjs.map +1 -1
- package/dist/development/src/providers.js +2 -2
- package/dist/development/src/providers.js.map +1 -1
- package/dist/development/src/transfer/ImportApiMiddlewareFactory.cjs +2 -2
- package/dist/development/src/transfer/ImportApiMiddlewareFactory.cjs.map +1 -1
- package/dist/development/src/transfer/ImportExecutor.cjs +18 -3
- package/dist/development/src/transfer/ImportExecutor.cjs.map +1 -1
- package/dist/development/src/transfer/ImportExecutor.js +18 -3
- package/dist/development/src/transfer/ImportExecutor.js.map +1 -1
- package/dist/development/src/utils/sentry.cjs +31 -49
- package/dist/development/src/utils/sentry.cjs.map +1 -1
- package/dist/development/src/utils/sentry.js +32 -33
- package/dist/development/src/utils/sentry.js.map +1 -1
- package/dist/development/src/utils/serverStartup.cjs +5 -3
- package/dist/development/src/utils/serverStartup.cjs.map +1 -1
- package/dist/development/src/utils/serverStartup.js +5 -3
- package/dist/development/src/utils/serverStartup.js.map +1 -1
- package/dist/production/index.cjs +0 -1
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.js +1 -2
- package/dist/production/src/application/application.cjs +8 -9
- package/dist/production/src/application/application.cjs.map +1 -1
- package/dist/production/src/application/application.js +8 -9
- package/dist/production/src/application/application.js.map +1 -1
- package/dist/production/src/application/compression.cjs +99 -0
- package/dist/production/src/application/compression.cjs.map +1 -0
- package/dist/production/src/application/compression.js +82 -0
- package/dist/production/src/application/compression.js.map +1 -0
- package/dist/production/src/application/cors.cjs +52 -0
- package/dist/production/src/application/cors.cjs.map +1 -0
- package/dist/production/src/application/cors.js +52 -0
- package/dist/production/src/application/cors.js.map +1 -0
- package/dist/production/src/application/requestBody.cjs +242 -0
- package/dist/production/src/application/requestBody.cjs.map +1 -0
- package/dist/production/src/application/requestBody.js +242 -0
- package/dist/production/src/application/requestBody.js.map +1 -0
- package/dist/production/src/config/configSchema.cjs +8 -1
- package/dist/production/src/config/configSchema.cjs.map +1 -1
- package/dist/production/src/config/configSchema.js +8 -1
- package/dist/production/src/config/configSchema.js.map +1 -1
- package/dist/production/src/graphql/execution.cjs +3 -9
- package/dist/production/src/graphql/execution.cjs.map +1 -1
- package/dist/production/src/graphql/execution.js +3 -9
- package/dist/production/src/graphql/execution.js.map +1 -1
- package/dist/production/src/project/ProjectContainer.cjs +1 -1
- package/dist/production/src/project/ProjectContainer.js +1 -1
- package/dist/production/src/projectGroup/ProjectGroupContainer.cjs +1 -1
- package/dist/production/src/projectGroup/ProjectGroupContainer.js +1 -1
- package/dist/production/src/providers.cjs +2 -2
- package/dist/production/src/providers.cjs.map +1 -1
- package/dist/production/src/providers.js +2 -2
- package/dist/production/src/providers.js.map +1 -1
- package/dist/production/src/transfer/ImportApiMiddlewareFactory.cjs +2 -2
- package/dist/production/src/transfer/ImportApiMiddlewareFactory.cjs.map +1 -1
- package/dist/production/src/transfer/ImportExecutor.cjs +18 -3
- package/dist/production/src/transfer/ImportExecutor.cjs.map +1 -1
- package/dist/production/src/transfer/ImportExecutor.js +18 -3
- package/dist/production/src/transfer/ImportExecutor.js.map +1 -1
- package/dist/production/src/utils/sentry.cjs +31 -49
- package/dist/production/src/utils/sentry.cjs.map +1 -1
- package/dist/production/src/utils/sentry.js +32 -33
- package/dist/production/src/utils/sentry.js.map +1 -1
- package/dist/production/src/utils/serverStartup.cjs +5 -3
- package/dist/production/src/utils/serverStartup.cjs.map +1 -1
- package/dist/production/src/utils/serverStartup.js +5 -3
- package/dist/production/src/utils/serverStartup.js.map +1 -1
- package/dist/tests/cases/unit/compression.test.d.ts +2 -0
- package/dist/tests/cases/unit/compression.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/cors.test.d.ts +2 -0
- package/dist/tests/cases/unit/cors.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/requestBody.test.d.ts +2 -0
- package/dist/tests/cases/unit/requestBody.test.d.ts.map +1 -0
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/MasterContainer.d.ts +1 -1
- package/dist/types/application/application.d.ts.map +1 -1
- package/dist/types/application/compression.d.ts +19 -0
- package/dist/types/application/compression.d.ts.map +1 -0
- package/dist/types/application/cors.d.ts +10 -0
- package/dist/types/application/cors.d.ts.map +1 -0
- package/dist/types/application/requestBody.d.ts +45 -0
- package/dist/types/application/requestBody.d.ts.map +1 -0
- package/dist/types/config/configSchema.d.ts +3 -3
- package/dist/types/config/configSchema.d.ts.map +1 -1
- package/dist/types/graphql/execution.d.ts.map +1 -1
- package/dist/types/transfer/ImportExecutor.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/utils/sentry.d.ts +13 -6
- package/dist/types/utils/sentry.d.ts.map +1 -1
- package/dist/types/utils/serverStartup.d.ts.map +1 -1
- package/package.json +18 -24
- package/src/application/application.ts +8 -9
- package/src/application/compression.ts +118 -0
- package/src/application/cors.ts +61 -0
- package/src/application/requestBody.ts +295 -0
- package/src/config/configSchema.ts +8 -1
- package/src/graphql/execution.ts +3 -9
- package/src/providers.ts +2 -2
- package/src/transfer/ImportExecutor.ts +21 -3
- package/src/tsconfig.json +3 -1
- package/src/utils/sentry.ts +42 -39
- package/src/utils/serverStartup.ts +7 -5
- package/tests/cases/unit/compression.test.ts +172 -0
- package/tests/cases/unit/cors.test.ts +106 -0
- package/tests/cases/unit/requestBody.test.ts +333 -0
- package/tests/cases/unit/sentryLoggerHandler.test.ts +74 -20
- package/tests/cases/unit/serverConfig.test.ts +19 -0
- package/dist/tests/cases/unit/sentryIntegrations.test.d.ts +0 -2
- package/dist/tests/cases/unit/sentryIntegrations.test.d.ts.map +0 -1
- package/tests/cases/unit/sentryIntegrations.test.ts +0 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImportExecutor.js","sources":["../../../../../packages/engine-http/src/transfer/ImportExecutor.ts"],"sourcesContent":["import { Client, Connection, ConstraintHelper, DatabaseMetadataResolver, wrapIdentifier } from '@contember/database'\nimport { Model, Schema } from '@contember/schema'\nimport * as Typesafe from '@contember/typesafe'\nimport { ParseError } from '@contember/typesafe'\nimport { Command, CommandArgsMap, CommandName } from './Command.js'\nimport { DatabaseContext, StageBySlugQuery } from '@contember/engine-system-api'\nimport { DbColumnSchema, TransferMapping, TransferTableMapping } from './TransferMapping.js'\nimport { ContentSchemaTransferMappingFactory } from './ContentSchemaTransferMappingFactory.js'\nimport { SystemSchemaTransferMappingFactory } from './SystemSchemaTransferMappingFactory.js'\nimport { AuthResult, HttpErrorResponse } from '../common/index.js'\nimport { ProjectGroupContainer } from '../projectGroup/ProjectGroupContainer.js'\n\ntype Cell = boolean | number | string | readonly string[] | readonly number[] | readonly boolean[] | null\ntype Row = readonly Cell[]\n\ntype InsertContext = {\n\ttableName: string\n\tinsertStartFragment: string\n\trowFragment: string\n\trowParser: Typesafe.Type<Row>\n\trows: Array<Row>\n\tinsertedRowCount: number\n}\n\nexport class ImportError extends Error {\n}\n\nconst parsePgTextArray = (value: string): string[] => {\n\tif (value === '{}') return []\n\tif (!value.startsWith('{') || !value.endsWith('}')) {\n\t\tthrow new ParseError([], `invalid PostgreSQL array literal: ${value}`)\n\t}\n\tconst inner = value.slice(1, -1)\n\tconst result: string[] = []\n\tlet current = ''\n\tlet inQuotes = false\n\tlet escaped = false\n\tfor (const ch of inner) {\n\t\tif (escaped) {\n\t\t\tcurrent += ch\n\t\t\tescaped = false\n\t\t} else if (ch === '\\\\') {\n\t\t\tescaped = true\n\t\t} else if (ch === '\"') {\n\t\t\tinQuotes = !inQuotes\n\t\t} else if (ch === ',' && !inQuotes) {\n\t\t\tresult.push(current)\n\t\t\tcurrent = ''\n\t\t} else {\n\t\t\tcurrent += ch\n\t\t}\n\t}\n\tresult.push(current)\n\treturn result\n}\n\nconst listType = <T extends Typesafe.Json>(arrayType: Typesafe.Type<T>): Typesafe.Type<T> => {\n\treturn (input: unknown, path: PropertyKey[] = []) => {\n\t\tif (Array.isArray(input)) {\n\t\t\treturn arrayType(input, path)\n\t\t}\n\t\tif (typeof input === 'string' && input.startsWith('{')) {\n\t\t\treturn arrayType(parsePgTextArray(input), path)\n\t\t}\n\t\treturn arrayType(input, path)\n\t}\n}\n\ntype CommandProcessor<T extends CommandName> = (it: CommandIterator<T>) => Promise<CommandIterator | null>\ntype CommandProcessorMap<T extends CommandName> = { [N in CommandName]?: N extends T ? CommandProcessor<N> : undefined }\n\nclass CommandIterator<T extends CommandName = CommandName> {\n\tprivate constructor(\n\t\tpublic readonly commandName: T,\n\t\tpublic readonly commandArgs: CommandArgsMap[T],\n\t\tprivate readonly commandIterator: AsyncIterator<Command>,\n\t) {\n\t}\n\n\tpublic static async create(commands: AsyncIterable<Command>): Promise<CommandIterator | null> {\n\t\tconst commandIterator = commands[Symbol.asyncIterator]()\n\t\tconst result = await commandIterator.next()\n\n\t\tif (result.done) {\n\t\t\treturn null\n\t\t}\n\n\t\tconst [name, ...args] = result.value\n\t\treturn new CommandIterator(name, args, commandIterator)\n\t}\n\n\tasync next(): Promise<CommandIterator | null> {\n\t\tconst result = await this.commandIterator.next()\n\n\t\tif (result.done) {\n\t\t\treturn null\n\t\t}\n\n\t\tconst [name, ...args] = result.value\n\t\treturn new CommandIterator(name, args, this.commandIterator)\n\t}\n}\n\nexport class ImportExecutor {\n\tconstructor(\n\t\tprivate readonly contentSchemaTransferMappingFactory: ContentSchemaTransferMappingFactory,\n\t\tprivate readonly systemSchemaTransferMappingFactory: SystemSchemaTransferMappingFactory,\n\t\tprivate readonly databaseMetadataResolver: DatabaseMetadataResolver,\n\t) {\n\t}\n\n\tasync import(groupContainer: ProjectGroupContainer, authResult: AuthResult, commands: AsyncIterable<Command>) {\n\t\tconst it = await CommandIterator.create(commands)\n\n\t\tconst final = await this.match(it, {\n\t\t\timportContentSchemaBegin: it => this.importContentSchemaBegin(groupContainer, authResult, it),\n\t\t\timportSystemSchemaBegin: it => this.importSystemSchemaBegin(groupContainer, authResult, it),\n\t\t})\n\n\t\tif (final !== null) {\n\t\t\tthrow new ImportError(`Unexpected ${final.commandName}`)\n\t\t}\n\t}\n\n\tprivate async match<T extends CommandName>(it: CommandIterator<T> | null, processors: CommandProcessorMap<T>) {\n\t\tlet next: CommandIterator | null = it\n\n\t\twhile (next !== null) {\n\t\t\tconst processor = processors[next.commandName]\n\n\t\t\tif (processor) {\n\t\t\t\tnext = await processor(next as any)\n\t\t\t} else {\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\treturn next\n\t}\n\n\tprivate async importContentSchemaBegin(\n\t\tgroupContainer: ProjectGroupContainer,\n\t\tauthResult: AuthResult,\n\t\tit: CommandIterator<'importContentSchemaBegin'>,\n\t) {\n\t\tconst [options] = it.commandArgs\n\t\tconst projectContainer = await this.createProjectContainer(groupContainer, options.project)\n\t\tconst systemDatabaseContext = projectContainer.systemDatabaseContext\n\t\tconst stage = await this.fetchStageBySlug(systemDatabaseContext, options.project, options.stage)\n\n\t\tconst contentSchema = await projectContainer.contentSchemaResolver.getSchema({ db: systemDatabaseContext, stage: stage.slug, normalize: true })\n\n\t\tif (contentSchema.meta.version !== options.schemaVersion) {\n\t\t\tthrow new ImportError(\n\t\t\t\t`Incompatible schema version (import version ${options.schemaVersion} does not match server version ${contentSchema.meta.version})`,\n\t\t\t)\n\t\t}\n\n\t\tawait this.requireImportAccess(groupContainer, contentSchema.schema, authResult, options.project, 'content')\n\t\tconst contentDatabaseClient = projectContainer.connection.createClient(stage.schema, {})\n\t\tconst mapping = this.contentSchemaTransferMappingFactory.createContentSchemaMapping(contentSchema.schema)\n\t\tthis.requireMappedTables(mapping, options.tables, `content schema of project ${options.project}`)\n\n\t\treturn await contentDatabaseClient.transaction(async db => {\n\t\t\tawait this.disableTimeouts(db)\n\t\t\tawait this.disableTriggers(db, options.tables)\n\t\t\tawait this.lockTables(db, options.tables)\n\t\t\tawait this.truncateTables(db, options.tables)\n\n\t\t\tconst metadata = await this.databaseMetadataResolver.resolveMetadata(db, db.schema)\n\t\t\tconst constraintHelper = new ConstraintHelper(db, metadata)\n\t\t\tawait constraintHelper.setConstraintsDeferred('foreignKey')\n\n\t\t\tconst result = await this.match(await it.next(), {\n\t\t\t\timportSequence: it => this.importSequence(db, mapping, it),\n\t\t\t\tinsertBegin: it => this.insertBegin(db, mapping, it),\n\t\t\t})\n\n\t\t\tawait constraintHelper.setConstraintsImmediate('foreignKey')\n\t\t\tawait this.enableTriggers(db, options.tables)\n\n\t\t\treturn result\n\t\t})\n\t}\n\n\tprivate async importSystemSchemaBegin(\n\t\tgroupContainer: ProjectGroupContainer,\n\t\tauthResult: AuthResult,\n\t\tit: CommandIterator<'importSystemSchemaBegin'>,\n\t) {\n\t\tconst [options] = it.commandArgs\n\t\tconst projectContainer = await this.createProjectContainer(groupContainer, options.project)\n\t\tconst schema = await groupContainer.projectSchemaResolver.getSchema(options.project)\n\n\t\tif (schema === undefined) {\n\t\t\tthrow new ImportError(`Project ${options.project} does not have schema`)\n\t\t}\n\n\t\tawait this.requireImportAccess(groupContainer, schema, authResult, options.project, 'system')\n\t\tconst systemDatabaseContext = projectContainer.systemDatabaseContext\n\t\tconst mapping = this.systemSchemaTransferMappingFactory.build()\n\t\tthis.requireMappedTables(mapping, options.tables, `system schema of project ${options.project}`)\n\n\t\treturn await systemDatabaseContext.client.transaction(async db => {\n\t\t\tawait this.disableTimeouts(db)\n\t\t\tawait this.truncateTables(db, options.tables)\n\n\t\t\tconst metadata = await this.databaseMetadataResolver.resolveMetadata(db, db.schema)\n\t\t\tconst constraintHelper = new ConstraintHelper(db, metadata)\n\t\t\tawait constraintHelper.setConstraintsDeferred('foreignKey')\n\n\t\t\treturn await this.match(await it.next(), {\n\t\t\t\tinsertBegin: it => this.insertBegin(db, mapping, it),\n\t\t\t})\n\t\t})\n\t}\n\n\tprivate async importSequence(\n\t\tdb: Client<Connection.TransactionLike>,\n\t\tmapping: TransferMapping,\n\t\tit: CommandIterator<'importSequence'>,\n\t): Promise<CommandIterator | null> {\n\t\tconst [options] = it.commandArgs\n\t\tif (!Object.hasOwn(mapping.tables, options.table) || !Object.hasOwn(mapping.tables[options.table].columns, options.column)) {\n\t\t\tthrow new ImportError(`Unknown column ${options.table}.${options.column}`)\n\t\t}\n\n\t\tawait db.query(\n\t\t\t'SELECT setval(pg_get_serial_sequence(?, ?), ?)',\n\t\t\t[`${db.schema}.${options.table}`, options.column, options.value],\n\t\t)\n\n\t\treturn it.next()\n\t}\n\n\tprivate async insertBegin(\n\t\tdb: Client<Connection.TransactionLike>,\n\t\tmapping: TransferMapping,\n\t\tit: CommandIterator<'insertBegin'>,\n\t): Promise<CommandIterator | null> {\n\t\tconst [options] = it.commandArgs\n\t\tconst insertContext = await this.buildInsertContext(db, mapping, db.schema, options.table, options.columns)\n\t\tlet insertRowsPromise: Promise<Connection.Result> | null = null\n\n\t\t// postgresql has a limit of 65535 parameters per query\n\t\tconst batchSize = Math.max(1, Math.min(1000, Math.floor(65500 / options.columns.length)))\n\n\t\tconst result = await this.match(await it.next(), {\n\t\t\tinsertRow: async it => {\n\t\t\t\tconst [values] = it.commandArgs\n\n\t\t\t\ttry {\n\t\t\t\t\tinsertContext.rows.push(insertContext.rowParser(values))\n\t\t\t\t} catch (e) {\n\t\t\t\t\tif (e instanceof ParseError) {\n\t\t\t\t\t\tthrow new ImportError(`Invalid row ${JSON.stringify(values)} for table ${options.table}: ${e.message}`)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow e\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (insertContext.rows.length === batchSize) {\n\t\t\t\t\tawait insertRowsPromise\n\t\t\t\t\tinsertRowsPromise = this.insertRows(db, insertContext)\n\t\t\t\t\tinsertContext.insertedRowCount += insertContext.rows.length\n\t\t\t\t\tinsertContext.rows = []\n\t\t\t\t}\n\n\t\t\t\treturn await it.next()\n\t\t\t},\n\t\t})\n\n\t\tif (insertContext.rows.length > 0) {\n\t\t\tawait insertRowsPromise\n\t\t\tawait this.insertRows(db, insertContext)\n\t\t\tinsertContext.insertedRowCount += insertContext.rows.length\n\t\t\tinsertContext.rows = []\n\t\t}\n\n\t\tif (result === null || result.commandName !== 'insertEnd') {\n\t\t\tthrow new ImportError(`Missing insertEnd command`)\n\t\t}\n\n\t\treturn await result.next()\n\t}\n\n\tprivate async createProjectContainer(groupContainer: ProjectGroupContainer, projectSlug: string) {\n\t\tconst projectContainerResolver = groupContainer.projectContainerResolver\n\t\tconst projectContainer = await projectContainerResolver.getProjectContainer(projectSlug, { alias: true })\n\n\t\tif (projectContainer === undefined) {\n\t\t\tthrow new ImportError(`Project ${projectSlug} does not exists.`)\n\t\t}\n\n\t\treturn projectContainer\n\t}\n\n\tprivate async requireImportAccess(\n\t\tgroupContainer: ProjectGroupContainer,\n\t\tschema: Schema,\n\t\tauthResult: AuthResult,\n\t\tprojectSlug: string,\n\t\tkind: 'content' | 'system',\n\t) {\n\t\tconst { effective: memberships } = await groupContainer.projectMembershipResolver.resolveMemberships({\n\t\t\trequest: { get: () => '' },\n\t\t\tacl: schema.acl,\n\t\t\tprojectSlug: projectSlug,\n\t\t\tidentity: {\n\t\t\t\tidentityId: authResult.identityId,\n\t\t\t\troles: authResult.roles,\n\t\t\t},\n\t\t})\n\n\t\tconst projectRoles = memberships.map(it => it.role)\n\n\t\tif (!projectRoles.some(role => schema.acl.roles[role]?.[kind]?.import)) {\n\t\t\tthrow new HttpErrorResponse(403, `You are not allowed to import ${kind} in ${projectSlug}`)\n\t\t}\n\t}\n\n\t/** The tables an import truncates must come from the same mapping an export of this schema lists. */\n\tprivate requireMappedTables(mapping: TransferMapping, tableNames: readonly string[], target: string) {\n\t\tfor (const tableName of tableNames) {\n\t\t\tif (!Object.hasOwn(mapping.tables, tableName)) {\n\t\t\t\tthrow new ImportError(`Table ${tableName} is not part of the ${target}`)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async fetchStageBySlug(systemDatabaseContext: DatabaseContext, projectSlug: string, stageSlug: string) {\n\t\tconst stage = await systemDatabaseContext.queryHandler.fetch(new StageBySlugQuery(stageSlug))\n\n\t\tif (stage === null) {\n\t\t\tthrow new ImportError(`Project ${projectSlug} does not have stage ${stageSlug}.`)\n\t\t}\n\n\t\treturn stage\n\t}\n\n\tprivate async disableTriggers(db: Client, tableNames: readonly string[]) {\n\t\tfor (const tableName of tableNames) {\n\t\t\tconst tableNameQuoted = `${wrapIdentifier(db.schema)}.${wrapIdentifier(tableName)}`\n\t\t\tawait db.query(`ALTER TABLE ${tableNameQuoted} DISABLE TRIGGER USER`)\n\t\t}\n\t}\n\n\tprivate async enableTriggers(db: Client, tableNames: readonly string[]) {\n\t\tfor (const tableName of tableNames) {\n\t\t\tconst tableNameQuoted = `${wrapIdentifier(db.schema)}.${wrapIdentifier(tableName)}`\n\t\t\tawait db.query(`ALTER TABLE ${tableNameQuoted} ENABLE TRIGGER USER`)\n\t\t}\n\t}\n\n\tprivate async lockTables(db: Client, tableNames: readonly string[]) {\n\t\tconst tableNamesQuoted = tableNames.map(it => `${wrapIdentifier(db.schema)}.${wrapIdentifier(it)}`)\n\t\tawait db.query(`LOCK ${tableNamesQuoted.join(', ')} IN EXCLUSIVE MODE`)\n\t}\n\n\tprivate async truncateTables(db: Client, tableNames: readonly string[]) {\n\t\tconst tableNamesQuoted = tableNames.map(it => `${wrapIdentifier(db.schema)}.${wrapIdentifier(it)}`)\n\t\tawait db.query(`TRUNCATE ${tableNamesQuoted.join(', ')}`)\n\t}\n\n\tprivate async disableTimeouts(db: Client) {\n\t\tawait db.query('SET LOCAL statement_timeout = 0')\n\t\tawait db.query('SET LOCAL lock_timeout = 0')\n\t}\n\n\tprivate async insertRows(db: Client, context: InsertContext) {\n\t\tconst rowsFragment = context.rows.map(_ => context.rowFragment).join(',\\n')\n\t\tconst sql = context.insertStartFragment + rowsFragment\n\t\tconst parameters: Cell[] = []\n\n\t\tfor (const row of context.rows) {\n\t\t\tfor (const cell of row) {\n\t\t\t\tparameters.push(cell)\n\t\t\t}\n\t\t}\n\n\t\treturn await db.query(sql, parameters)\n\t}\n\n\tprivate async buildInsertContext(\n\t\tdb: Client,\n\t\tmapping: TransferMapping,\n\t\tschema: string,\n\t\ttableName: string,\n\t\tcolumnNames: readonly string[],\n\t): Promise<InsertContext> {\n\t\tconst tableMapping = Object.hasOwn(mapping.tables, tableName) ? mapping.tables[tableName] : undefined\n\t\tconst columns = []\n\n\t\tif (tableMapping === undefined) {\n\t\t\tthrow new ImportError(`Unknown table ${tableName}`)\n\t\t}\n\n\t\tfor (const columnName of columnNames) {\n\t\t\tconst column = Object.hasOwn(tableMapping.columns, columnName) ? tableMapping.columns[columnName] : undefined\n\n\t\t\tif (column === undefined) {\n\t\t\t\tthrow new ImportError(`Unknown column ${tableName}.${columnName}`)\n\t\t\t}\n\n\t\t\tcolumns.push(column)\n\t\t}\n\n\t\tconst insertStartFragment = (tableMapping.createInsertStartFragment ?? this.createInsertStartFragment)(schema, tableName, columnNames)\n\t\tconst rowFragment = '(' + columns.map(_ => '?').join(', ') + ')'\n\t\tconst rowParser = await this.buildRowParser(db, tableMapping, columns)\n\n\t\treturn {\n\t\t\ttableName,\n\t\t\tinsertStartFragment,\n\t\t\trowFragment,\n\t\t\trowParser,\n\t\t\trows: [],\n\t\t\tinsertedRowCount: 0,\n\t\t}\n\t}\n\n\tprivate createInsertStartFragment(schema: string, tableName: string, columnNames: readonly string[]): string {\n\t\tconst tableQuoted = `${wrapIdentifier(schema)}.${wrapIdentifier(tableName)}`\n\t\tconst columnsQuoted = '(' + columnNames.map(it => wrapIdentifier(it)).join(', ') + ')'\n\t\treturn `INSERT INTO ${tableQuoted} ${columnsQuoted} VALUES\\n`\n\t}\n\n\tprivate async buildRowParser(db: Client, tableMapping: TransferTableMapping, columns: DbColumnSchema[]): Promise<Typesafe.Type<readonly Cell[]>> {\n\t\tconst baseType = Typesafe.tuple(...columns.map(it => {\n\t\t\tconst base = this.buildColumnRuntimeType(it)\n\t\t\treturn it.nullable ? Typesafe.nullable(base) : base\n\t\t}))\n\n\t\tif (tableMapping.createRowParser === undefined) {\n\t\t\treturn baseType\n\t\t}\n\n\t\treturn await tableMapping.createRowParser(db, columns.map(it => it.name), baseType)\n\t}\n\n\tprivate buildColumnRuntimeType(column: DbColumnSchema): Typesafe.Type<Exclude<Cell, null>> {\n\t\tswitch (column.type) {\n\t\t\tcase Model.ColumnType.Uuid:\n\t\t\tcase Model.ColumnType.String:\n\t\t\tcase Model.ColumnType.Enum:\n\t\t\tcase Model.ColumnType.DateTime:\n\t\t\tcase Model.ColumnType.Time:\n\t\t\tcase Model.ColumnType.Date:\n\t\t\tcase Model.ColumnType.Json:\n\t\t\t// Numeric is transferred as a string to avoid JS float precision loss.\n\t\t\tcase Model.ColumnType.Numeric:\n\t\t\t\treturn column.list ? listType(Typesafe.array(Typesafe.string)) : Typesafe.string\n\t\t\tcase Model.ColumnType.Int:\n\t\t\tcase Model.ColumnType.Double:\n\t\t\t\treturn column.list ? listType(Typesafe.array(Typesafe.number)) : Typesafe.number\n\t\t\tcase Model.ColumnType.Bool:\n\t\t\t\treturn column.list ? listType(Typesafe.array(Typesafe.boolean)) : Typesafe.boolean\n\t\t}\n\t}\n}\n"],"names":["it"],"mappings":";;;;;;;;AAwBO,MAAM,oBAAoB,MAAM;AACvC;AAEA,MAAM,mBAAmB,CAAC,UAA4B;AACrD,MAAI,UAAU,KAAM,QAAO,CAAA;AAC3B,MAAI,CAAC,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,SAAS,GAAG,GAAG;AACnD,UAAM,IAAI,WAAW,CAAA,GAAI,qCAAqC,KAAK,EAAE;AAAA,EACtE;AACA,QAAM,QAAQ,MAAM,MAAM,GAAG,EAAE;AAC/B,QAAM,SAAmB,CAAA;AACzB,MAAI,UAAU;AACd,MAAI,WAAW;AACf,MAAI,UAAU;AACd,aAAW,MAAM,OAAO;AACvB,QAAI,SAAS;AACZ,iBAAW;AACX,gBAAU;AAAA,IACX,WAAW,OAAO,MAAM;AACvB,gBAAU;AAAA,IACX,WAAW,OAAO,KAAK;AACtB,iBAAW,CAAC;AAAA,IACb,WAAW,OAAO,OAAO,CAAC,UAAU;AACnC,aAAO,KAAK,OAAO;AACnB,gBAAU;AAAA,IACX,OAAO;AACN,iBAAW;AAAA,IACZ;AAAA,EACD;AACA,SAAO,KAAK,OAAO;AACnB,SAAO;AACR;AAEA,MAAM,WAAW,CAA0B,cAAkD;AAC5F,SAAO,CA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AAM,WAAW;AAAA;AAAA,MAEtB,KAAK,MAAM,WAAW;AACrB,eAAO,OAAO,OAAO,SAAS,SAAS,MAAM,SAAS,MAAM,CAAC,IAAI,SAAS;AAAA,MAC3E,KAAK,MAAM,WAAW;AAAA,MACtB,KAAK,MAAM,WAAW;AACrB,eAAO,OAAO,OAAO,SAAS,SAAS,MAAM,SAAS,MAAM,CAAC,IAAI,SAAS;AAAA,MAC3E,KAAK,MAAM,WAAW;AACrB,eAAO,OAAO,OAAO,SAAS,SAAS,MAAM,SAAS,OAAO,CAAC,IAAI,SAAS;AAAA,IAAA;AAAA,EAE9E;AACD;"}
|
|
1
|
+
{"version":3,"file":"ImportExecutor.js","sources":["../../../../../packages/engine-http/src/transfer/ImportExecutor.ts"],"sourcesContent":["import { Client, Connection, ConstraintHelper, DatabaseMetadataResolver, wrapIdentifier } from '@contember/database'\nimport { Model, Schema } from '@contember/schema'\nimport * as Typesafe from '@contember/typesafe'\nimport { ParseError } from '@contember/typesafe'\nimport { Command, CommandArgsMap, CommandName } from './Command.js'\nimport { DatabaseContext, StageBySlugQuery } from '@contember/engine-system-api'\nimport { isImpossibleCalendarDate } from '@contember/engine-content-api'\nimport { DbColumnSchema, TransferMapping, TransferTableMapping } from './TransferMapping.js'\nimport { ContentSchemaTransferMappingFactory } from './ContentSchemaTransferMappingFactory.js'\nimport { SystemSchemaTransferMappingFactory } from './SystemSchemaTransferMappingFactory.js'\nimport { AuthResult, HttpErrorResponse } from '../common/index.js'\nimport { ProjectGroupContainer } from '../projectGroup/ProjectGroupContainer.js'\n\ntype Cell = boolean | number | string | readonly string[] | readonly number[] | readonly boolean[] | null\ntype Row = readonly Cell[]\n\ntype InsertContext = {\n\ttableName: string\n\tinsertStartFragment: string\n\trowFragment: string\n\trowParser: Typesafe.Type<Row>\n\trows: Array<Row>\n\tinsertedRowCount: number\n}\n\nexport class ImportError extends Error {\n}\n\nconst parsePgTextArray = (value: string): string[] => {\n\tif (value === '{}') return []\n\tif (!value.startsWith('{') || !value.endsWith('}')) {\n\t\tthrow new ParseError([], `invalid PostgreSQL array literal: ${value}`)\n\t}\n\tconst inner = value.slice(1, -1)\n\tconst result: string[] = []\n\tlet current = ''\n\tlet inQuotes = false\n\tlet escaped = false\n\tfor (const ch of inner) {\n\t\tif (escaped) {\n\t\t\tcurrent += ch\n\t\t\tescaped = false\n\t\t} else if (ch === '\\\\') {\n\t\t\tescaped = true\n\t\t} else if (ch === '\"') {\n\t\t\tinQuotes = !inQuotes\n\t\t} else if (ch === ',' && !inQuotes) {\n\t\t\tresult.push(current)\n\t\t\tcurrent = ''\n\t\t} else {\n\t\t\tcurrent += ch\n\t\t}\n\t}\n\tresult.push(current)\n\treturn result\n}\n\nconst listType = <T extends Typesafe.Json>(arrayType: Typesafe.Type<T>): Typesafe.Type<T> => {\n\treturn (input: unknown, path: PropertyKey[] = []) => {\n\t\tif (Array.isArray(input)) {\n\t\t\treturn arrayType(input, path)\n\t\t}\n\t\tif (typeof input === 'string' && input.startsWith('{')) {\n\t\t\treturn arrayType(parsePgTextArray(input), path)\n\t\t}\n\t\treturn arrayType(input, path)\n\t}\n}\n\n// PostgreSQL would fail the whole batch insert on an impossible date with a server error that names neither column nor row.\nconst calendarDate: Typesafe.Type<string> = (input: unknown, path: PropertyKey[] = []) => {\n\tconst value = Typesafe.string(input, path)\n\tif (isImpossibleCalendarDate(value)) {\n\t\tthrow new ParseError(path, `${JSON.stringify(value)} is not a valid date`)\n\t}\n\treturn value\n}\n\ntype CommandProcessor<T extends CommandName> = (it: CommandIterator<T>) => Promise<CommandIterator | null>\ntype CommandProcessorMap<T extends CommandName> = { [N in CommandName]?: N extends T ? CommandProcessor<N> : undefined }\n\nclass CommandIterator<T extends CommandName = CommandName> {\n\tprivate constructor(\n\t\tpublic readonly commandName: T,\n\t\tpublic readonly commandArgs: CommandArgsMap[T],\n\t\tprivate readonly commandIterator: AsyncIterator<Command>,\n\t) {\n\t}\n\n\tpublic static async create(commands: AsyncIterable<Command>): Promise<CommandIterator | null> {\n\t\tconst commandIterator = commands[Symbol.asyncIterator]()\n\t\tconst result = await commandIterator.next()\n\n\t\tif (result.done) {\n\t\t\treturn null\n\t\t}\n\n\t\tconst [name, ...args] = result.value\n\t\treturn new CommandIterator(name, args, commandIterator)\n\t}\n\n\tasync next(): Promise<CommandIterator | null> {\n\t\tconst result = await this.commandIterator.next()\n\n\t\tif (result.done) {\n\t\t\treturn null\n\t\t}\n\n\t\tconst [name, ...args] = result.value\n\t\treturn new CommandIterator(name, args, this.commandIterator)\n\t}\n}\n\nexport class ImportExecutor {\n\tconstructor(\n\t\tprivate readonly contentSchemaTransferMappingFactory: ContentSchemaTransferMappingFactory,\n\t\tprivate readonly systemSchemaTransferMappingFactory: SystemSchemaTransferMappingFactory,\n\t\tprivate readonly databaseMetadataResolver: DatabaseMetadataResolver,\n\t) {\n\t}\n\n\tasync import(groupContainer: ProjectGroupContainer, authResult: AuthResult, commands: AsyncIterable<Command>) {\n\t\tconst it = await CommandIterator.create(commands)\n\n\t\tconst final = await this.match(it, {\n\t\t\timportContentSchemaBegin: it => this.importContentSchemaBegin(groupContainer, authResult, it),\n\t\t\timportSystemSchemaBegin: it => this.importSystemSchemaBegin(groupContainer, authResult, it),\n\t\t})\n\n\t\tif (final !== null) {\n\t\t\tthrow new ImportError(`Unexpected ${final.commandName}`)\n\t\t}\n\t}\n\n\tprivate async match<T extends CommandName>(it: CommandIterator<T> | null, processors: CommandProcessorMap<T>) {\n\t\tlet next: CommandIterator | null = it\n\n\t\twhile (next !== null) {\n\t\t\tconst processor = processors[next.commandName]\n\n\t\t\tif (processor) {\n\t\t\t\tnext = await processor(next as any)\n\t\t\t} else {\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\treturn next\n\t}\n\n\tprivate async importContentSchemaBegin(\n\t\tgroupContainer: ProjectGroupContainer,\n\t\tauthResult: AuthResult,\n\t\tit: CommandIterator<'importContentSchemaBegin'>,\n\t) {\n\t\tconst [options] = it.commandArgs\n\t\tconst projectContainer = await this.createProjectContainer(groupContainer, options.project)\n\t\tconst systemDatabaseContext = projectContainer.systemDatabaseContext\n\t\tconst stage = await this.fetchStageBySlug(systemDatabaseContext, options.project, options.stage)\n\n\t\tconst contentSchema = await projectContainer.contentSchemaResolver.getSchema({ db: systemDatabaseContext, stage: stage.slug, normalize: true })\n\n\t\tif (contentSchema.meta.version !== options.schemaVersion) {\n\t\t\tthrow new ImportError(\n\t\t\t\t`Incompatible schema version (import version ${options.schemaVersion} does not match server version ${contentSchema.meta.version})`,\n\t\t\t)\n\t\t}\n\n\t\tawait this.requireImportAccess(groupContainer, contentSchema.schema, authResult, options.project, 'content')\n\t\tconst contentDatabaseClient = projectContainer.connection.createClient(stage.schema, {})\n\t\tconst mapping = this.contentSchemaTransferMappingFactory.createContentSchemaMapping(contentSchema.schema)\n\t\tthis.requireMappedTables(mapping, options.tables, `content schema of project ${options.project}`)\n\n\t\treturn await contentDatabaseClient.transaction(async db => {\n\t\t\tawait this.disableTimeouts(db)\n\t\t\tawait this.disableTriggers(db, options.tables)\n\t\t\tawait this.lockTables(db, options.tables)\n\t\t\tawait this.truncateTables(db, options.tables)\n\n\t\t\tconst metadata = await this.databaseMetadataResolver.resolveMetadata(db, db.schema)\n\t\t\tconst constraintHelper = new ConstraintHelper(db, metadata)\n\t\t\tawait constraintHelper.setConstraintsDeferred('foreignKey')\n\n\t\t\tconst result = await this.match(await it.next(), {\n\t\t\t\timportSequence: it => this.importSequence(db, mapping, it),\n\t\t\t\tinsertBegin: it => this.insertBegin(db, mapping, it),\n\t\t\t})\n\n\t\t\tawait constraintHelper.setConstraintsImmediate('foreignKey')\n\t\t\tawait this.enableTriggers(db, options.tables)\n\n\t\t\treturn result\n\t\t})\n\t}\n\n\tprivate async importSystemSchemaBegin(\n\t\tgroupContainer: ProjectGroupContainer,\n\t\tauthResult: AuthResult,\n\t\tit: CommandIterator<'importSystemSchemaBegin'>,\n\t) {\n\t\tconst [options] = it.commandArgs\n\t\tconst projectContainer = await this.createProjectContainer(groupContainer, options.project)\n\t\tconst schema = await groupContainer.projectSchemaResolver.getSchema(options.project)\n\n\t\tif (schema === undefined) {\n\t\t\tthrow new ImportError(`Project ${options.project} does not have schema`)\n\t\t}\n\n\t\tawait this.requireImportAccess(groupContainer, schema, authResult, options.project, 'system')\n\t\tconst systemDatabaseContext = projectContainer.systemDatabaseContext\n\t\tconst mapping = this.systemSchemaTransferMappingFactory.build()\n\t\tthis.requireMappedTables(mapping, options.tables, `system schema of project ${options.project}`)\n\n\t\treturn await systemDatabaseContext.client.transaction(async db => {\n\t\t\tawait this.disableTimeouts(db)\n\t\t\tawait this.truncateTables(db, options.tables)\n\n\t\t\tconst metadata = await this.databaseMetadataResolver.resolveMetadata(db, db.schema)\n\t\t\tconst constraintHelper = new ConstraintHelper(db, metadata)\n\t\t\tawait constraintHelper.setConstraintsDeferred('foreignKey')\n\n\t\t\treturn await this.match(await it.next(), {\n\t\t\t\tinsertBegin: it => this.insertBegin(db, mapping, it),\n\t\t\t})\n\t\t})\n\t}\n\n\tprivate async importSequence(\n\t\tdb: Client<Connection.TransactionLike>,\n\t\tmapping: TransferMapping,\n\t\tit: CommandIterator<'importSequence'>,\n\t): Promise<CommandIterator | null> {\n\t\tconst [options] = it.commandArgs\n\t\tif (!Object.hasOwn(mapping.tables, options.table) || !Object.hasOwn(mapping.tables[options.table].columns, options.column)) {\n\t\t\tthrow new ImportError(`Unknown column ${options.table}.${options.column}`)\n\t\t}\n\n\t\tawait db.query(\n\t\t\t'SELECT setval(pg_get_serial_sequence(?, ?), ?)',\n\t\t\t[`${db.schema}.${options.table}`, options.column, options.value],\n\t\t)\n\n\t\treturn it.next()\n\t}\n\n\tprivate async insertBegin(\n\t\tdb: Client<Connection.TransactionLike>,\n\t\tmapping: TransferMapping,\n\t\tit: CommandIterator<'insertBegin'>,\n\t): Promise<CommandIterator | null> {\n\t\tconst [options] = it.commandArgs\n\t\tconst insertContext = await this.buildInsertContext(db, mapping, db.schema, options.table, options.columns)\n\t\tlet insertRowsPromise: Promise<Connection.Result> | null = null\n\n\t\t// postgresql has a limit of 65535 parameters per query\n\t\tconst batchSize = Math.max(1, Math.min(1000, Math.floor(65500 / options.columns.length)))\n\n\t\tconst result = await this.match(await it.next(), {\n\t\t\tinsertRow: async it => {\n\t\t\t\tconst [values] = it.commandArgs\n\n\t\t\t\ttry {\n\t\t\t\t\tinsertContext.rows.push(insertContext.rowParser(values))\n\t\t\t\t} catch (e) {\n\t\t\t\t\tif (e instanceof ParseError) {\n\t\t\t\t\t\tconst rowNumber = insertContext.insertedRowCount + insertContext.rows.length + 1\n\t\t\t\t\t\t// The row parser is a tuple over the insertBegin columns, so the first path segment is the column index.\n\t\t\t\t\t\tconst [columnIndex, ...valuePath] = e.path\n\t\t\t\t\t\tconst columnName = columnIndex !== undefined ? options.columns[Number(columnIndex)] : undefined\n\t\t\t\t\t\tconst elementLocation = valuePath.length > 0 ? `, element /${valuePath.map(String).join('/')}` : ''\n\t\t\t\t\t\tconst location = columnName !== undefined ? `table ${options.table}, column ${columnName}${elementLocation}` : `table ${options.table}`\n\t\t\t\t\t\tconst reason = columnName !== undefined ? e.reason : e.message\n\t\t\t\t\t\tthrow new ImportError(`Invalid row #${rowNumber} ${JSON.stringify(values)} for ${location}: ${reason}`)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow e\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (insertContext.rows.length === batchSize) {\n\t\t\t\t\tawait insertRowsPromise\n\t\t\t\t\tinsertRowsPromise = this.insertRows(db, insertContext)\n\t\t\t\t\tinsertContext.insertedRowCount += insertContext.rows.length\n\t\t\t\t\tinsertContext.rows = []\n\t\t\t\t}\n\n\t\t\t\treturn await it.next()\n\t\t\t},\n\t\t})\n\n\t\tif (insertContext.rows.length > 0) {\n\t\t\tawait insertRowsPromise\n\t\t\tawait this.insertRows(db, insertContext)\n\t\t\tinsertContext.insertedRowCount += insertContext.rows.length\n\t\t\tinsertContext.rows = []\n\t\t}\n\n\t\tif (result === null || result.commandName !== 'insertEnd') {\n\t\t\tthrow new ImportError(`Missing insertEnd command`)\n\t\t}\n\n\t\treturn await result.next()\n\t}\n\n\tprivate async createProjectContainer(groupContainer: ProjectGroupContainer, projectSlug: string) {\n\t\tconst projectContainerResolver = groupContainer.projectContainerResolver\n\t\tconst projectContainer = await projectContainerResolver.getProjectContainer(projectSlug, { alias: true })\n\n\t\tif (projectContainer === undefined) {\n\t\t\tthrow new ImportError(`Project ${projectSlug} does not exists.`)\n\t\t}\n\n\t\treturn projectContainer\n\t}\n\n\tprivate async requireImportAccess(\n\t\tgroupContainer: ProjectGroupContainer,\n\t\tschema: Schema,\n\t\tauthResult: AuthResult,\n\t\tprojectSlug: string,\n\t\tkind: 'content' | 'system',\n\t) {\n\t\tconst { effective: memberships } = await groupContainer.projectMembershipResolver.resolveMemberships({\n\t\t\trequest: { get: () => '' },\n\t\t\tacl: schema.acl,\n\t\t\tprojectSlug: projectSlug,\n\t\t\tidentity: {\n\t\t\t\tidentityId: authResult.identityId,\n\t\t\t\troles: authResult.roles,\n\t\t\t},\n\t\t})\n\n\t\tconst projectRoles = memberships.map(it => it.role)\n\n\t\tif (!projectRoles.some(role => schema.acl.roles[role]?.[kind]?.import)) {\n\t\t\tthrow new HttpErrorResponse(403, `You are not allowed to import ${kind} in ${projectSlug}`)\n\t\t}\n\t}\n\n\t/** The tables an import truncates must come from the same mapping an export of this schema lists. */\n\tprivate requireMappedTables(mapping: TransferMapping, tableNames: readonly string[], target: string) {\n\t\tfor (const tableName of tableNames) {\n\t\t\tif (!Object.hasOwn(mapping.tables, tableName)) {\n\t\t\t\tthrow new ImportError(`Table ${tableName} is not part of the ${target}`)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async fetchStageBySlug(systemDatabaseContext: DatabaseContext, projectSlug: string, stageSlug: string) {\n\t\tconst stage = await systemDatabaseContext.queryHandler.fetch(new StageBySlugQuery(stageSlug))\n\n\t\tif (stage === null) {\n\t\t\tthrow new ImportError(`Project ${projectSlug} does not have stage ${stageSlug}.`)\n\t\t}\n\n\t\treturn stage\n\t}\n\n\tprivate async disableTriggers(db: Client, tableNames: readonly string[]) {\n\t\tfor (const tableName of tableNames) {\n\t\t\tconst tableNameQuoted = `${wrapIdentifier(db.schema)}.${wrapIdentifier(tableName)}`\n\t\t\tawait db.query(`ALTER TABLE ${tableNameQuoted} DISABLE TRIGGER USER`)\n\t\t}\n\t}\n\n\tprivate async enableTriggers(db: Client, tableNames: readonly string[]) {\n\t\tfor (const tableName of tableNames) {\n\t\t\tconst tableNameQuoted = `${wrapIdentifier(db.schema)}.${wrapIdentifier(tableName)}`\n\t\t\tawait db.query(`ALTER TABLE ${tableNameQuoted} ENABLE TRIGGER USER`)\n\t\t}\n\t}\n\n\tprivate async lockTables(db: Client, tableNames: readonly string[]) {\n\t\tconst tableNamesQuoted = tableNames.map(it => `${wrapIdentifier(db.schema)}.${wrapIdentifier(it)}`)\n\t\tawait db.query(`LOCK ${tableNamesQuoted.join(', ')} IN EXCLUSIVE MODE`)\n\t}\n\n\tprivate async truncateTables(db: Client, tableNames: readonly string[]) {\n\t\tconst tableNamesQuoted = tableNames.map(it => `${wrapIdentifier(db.schema)}.${wrapIdentifier(it)}`)\n\t\tawait db.query(`TRUNCATE ${tableNamesQuoted.join(', ')}`)\n\t}\n\n\tprivate async disableTimeouts(db: Client) {\n\t\tawait db.query('SET LOCAL statement_timeout = 0')\n\t\tawait db.query('SET LOCAL lock_timeout = 0')\n\t}\n\n\tprivate async insertRows(db: Client, context: InsertContext) {\n\t\tconst rowsFragment = context.rows.map(_ => context.rowFragment).join(',\\n')\n\t\tconst sql = context.insertStartFragment + rowsFragment\n\t\tconst parameters: Cell[] = []\n\n\t\tfor (const row of context.rows) {\n\t\t\tfor (const cell of row) {\n\t\t\t\tparameters.push(cell)\n\t\t\t}\n\t\t}\n\n\t\treturn await db.query(sql, parameters)\n\t}\n\n\tprivate async buildInsertContext(\n\t\tdb: Client,\n\t\tmapping: TransferMapping,\n\t\tschema: string,\n\t\ttableName: string,\n\t\tcolumnNames: readonly string[],\n\t): Promise<InsertContext> {\n\t\tconst tableMapping = Object.hasOwn(mapping.tables, tableName) ? mapping.tables[tableName] : undefined\n\t\tconst columns = []\n\n\t\tif (tableMapping === undefined) {\n\t\t\tthrow new ImportError(`Unknown table ${tableName}`)\n\t\t}\n\n\t\tfor (const columnName of columnNames) {\n\t\t\tconst column = Object.hasOwn(tableMapping.columns, columnName) ? tableMapping.columns[columnName] : undefined\n\n\t\t\tif (column === undefined) {\n\t\t\t\tthrow new ImportError(`Unknown column ${tableName}.${columnName}`)\n\t\t\t}\n\n\t\t\tcolumns.push(column)\n\t\t}\n\n\t\tconst insertStartFragment = (tableMapping.createInsertStartFragment ?? this.createInsertStartFragment)(schema, tableName, columnNames)\n\t\tconst rowFragment = '(' + columns.map(_ => '?').join(', ') + ')'\n\t\tconst rowParser = await this.buildRowParser(db, tableMapping, columns)\n\n\t\treturn {\n\t\t\ttableName,\n\t\t\tinsertStartFragment,\n\t\t\trowFragment,\n\t\t\trowParser,\n\t\t\trows: [],\n\t\t\tinsertedRowCount: 0,\n\t\t}\n\t}\n\n\tprivate createInsertStartFragment(schema: string, tableName: string, columnNames: readonly string[]): string {\n\t\tconst tableQuoted = `${wrapIdentifier(schema)}.${wrapIdentifier(tableName)}`\n\t\tconst columnsQuoted = '(' + columnNames.map(it => wrapIdentifier(it)).join(', ') + ')'\n\t\treturn `INSERT INTO ${tableQuoted} ${columnsQuoted} VALUES\\n`\n\t}\n\n\tprivate async buildRowParser(db: Client, tableMapping: TransferTableMapping, columns: DbColumnSchema[]): Promise<Typesafe.Type<readonly Cell[]>> {\n\t\tconst baseType = Typesafe.tuple(...columns.map(it => {\n\t\t\tconst base = this.buildColumnRuntimeType(it)\n\t\t\treturn it.nullable ? Typesafe.nullable(base) : base\n\t\t}))\n\n\t\tif (tableMapping.createRowParser === undefined) {\n\t\t\treturn baseType\n\t\t}\n\n\t\treturn await tableMapping.createRowParser(db, columns.map(it => it.name), baseType)\n\t}\n\n\tprivate buildColumnRuntimeType(column: DbColumnSchema): Typesafe.Type<Exclude<Cell, null>> {\n\t\tswitch (column.type) {\n\t\t\tcase Model.ColumnType.Uuid:\n\t\t\tcase Model.ColumnType.String:\n\t\t\tcase Model.ColumnType.Enum:\n\t\t\tcase Model.ColumnType.Time:\n\t\t\tcase Model.ColumnType.Json:\n\t\t\t// Numeric is transferred as a string to avoid JS float precision loss.\n\t\t\tcase Model.ColumnType.Numeric:\n\t\t\t\treturn column.list ? listType(Typesafe.array(Typesafe.string)) : Typesafe.string\n\t\t\tcase Model.ColumnType.Date:\n\t\t\tcase Model.ColumnType.DateTime:\n\t\t\t\treturn column.list ? listType(Typesafe.array(calendarDate)) : calendarDate\n\t\t\tcase Model.ColumnType.Int:\n\t\t\tcase Model.ColumnType.Double:\n\t\t\t\treturn column.list ? listType(Typesafe.array(Typesafe.number)) : Typesafe.number\n\t\t\tcase Model.ColumnType.Bool:\n\t\t\t\treturn column.list ? listType(Typesafe.array(Typesafe.boolean)) : Typesafe.boolean\n\t\t}\n\t}\n}\n"],"names":["it"],"mappings":";;;;;;;;;AAyBO,MAAM,oBAAoB,MAAM;AACvC;AAEA,MAAM,mBAAmB,CAAC,UAA4B;AACrD,MAAI,UAAU,KAAM,QAAO,CAAA;AAC3B,MAAI,CAAC,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,SAAS,GAAG,GAAG;AACnD,UAAM,IAAI,WAAW,CAAA,GAAI,qCAAqC,KAAK,EAAE;AAAA,EACtE;AACA,QAAM,QAAQ,MAAM,MAAM,GAAG,EAAE;AAC/B,QAAM,SAAmB,CAAA;AACzB,MAAI,UAAU;AACd,MAAI,WAAW;AACf,MAAI,UAAU;AACd,aAAW,MAAM,OAAO;AACvB,QAAI,SAAS;AACZ,iBAAW;AACX,gBAAU;AAAA,IACX,WAAW,OAAO,MAAM;AACvB,gBAAU;AAAA,IACX,WAAW,OAAO,KAAK;AACtB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AAO,OAAO,SAAS,SAAS,MAAM,SAAS,OAAO,CAAC,IAAI,SAAS;AAAA,IAAA;AAAA,EAE9E;AACD;"}
|
|
@@ -1,26 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const Sentry = require("@sentry/node");
|
|
4
3
|
const logger = require("@contember/logger");
|
|
4
|
+
const sentryClient = require("@contember/sentry-client");
|
|
5
5
|
const application = require("../application/application.cjs");
|
|
6
6
|
require("../application/requestBodyMasking.cjs");
|
|
7
|
-
function _interopNamespaceDefault(e) {
|
|
8
|
-
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
9
|
-
if (e) {
|
|
10
|
-
for (const k in e) {
|
|
11
|
-
if (k !== "default") {
|
|
12
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
get: () => e[k]
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
n.default = e;
|
|
21
|
-
return Object.freeze(n);
|
|
22
|
-
}
|
|
23
|
-
const Sentry__namespace = /* @__PURE__ */ _interopNamespaceDefault(Sentry);
|
|
24
7
|
const logLevelMapping = {
|
|
25
8
|
crit: "fatal",
|
|
26
9
|
error: "error",
|
|
@@ -28,9 +11,11 @@ const logLevelMapping = {
|
|
|
28
11
|
debug: "debug",
|
|
29
12
|
info: "info"
|
|
30
13
|
};
|
|
14
|
+
const stringAttribute = (value) => typeof value === "string" ? value : void 0;
|
|
31
15
|
class SentryLoggerHandler {
|
|
32
|
-
constructor(logLevel) {
|
|
16
|
+
constructor(logLevel, client) {
|
|
33
17
|
this.logLevel = logLevel;
|
|
18
|
+
this.client = client;
|
|
34
19
|
}
|
|
35
20
|
getMinLevel() {
|
|
36
21
|
return this.logLevel.value;
|
|
@@ -39,45 +24,42 @@ class SentryLoggerHandler {
|
|
|
39
24
|
if (!entry.error || entry.level.value < this.logLevel.value) {
|
|
40
25
|
return;
|
|
41
26
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const spanId = entry.loggerAttributes.spanId;
|
|
54
|
-
return {
|
|
55
|
-
...event,
|
|
56
|
-
request: {
|
|
57
|
-
url: entry.loggerAttributes.url ?? entry.ownAttributes.url,
|
|
58
|
-
data: entry.loggerAttributes[application.LoggerRequestBody]
|
|
59
|
-
},
|
|
60
|
-
...typeof traceId === "string" && typeof spanId === "string" ? { contexts: { ...event.contexts, trace: { trace_id: traceId, span_id: spanId } } } : {}
|
|
61
|
-
};
|
|
62
|
-
});
|
|
63
|
-
return scope;
|
|
27
|
+
const attribute = (name) => stringAttribute(entry.loggerAttributes[name] ?? entry.ownAttributes[name]);
|
|
28
|
+
const traceId = stringAttribute(entry.loggerAttributes.traceId);
|
|
29
|
+
const spanId = stringAttribute(entry.loggerAttributes.spanId);
|
|
30
|
+
this.client.captureException(entry.error, {
|
|
31
|
+
level: logLevelMapping[entry.level.name],
|
|
32
|
+
tags: { project: attribute("project"), projectGroup: attribute("projectGroup"), module: attribute("module") },
|
|
33
|
+
user: { id: attribute("user") },
|
|
34
|
+
extra: { requestId: entry.loggerAttributes.requestId },
|
|
35
|
+
// the request logger sets `uri`, already masked by maskRequestUri
|
|
36
|
+
request: { url: attribute("uri"), data: entry.loggerAttributes[application.LoggerRequestBody] },
|
|
37
|
+
...traceId !== void 0 && spanId !== void 0 ? { contexts: { trace: { trace_id: traceId, span_id: spanId } } } : {}
|
|
64
38
|
});
|
|
65
39
|
}
|
|
66
40
|
close() {
|
|
67
41
|
}
|
|
68
42
|
}
|
|
69
|
-
const
|
|
70
|
-
const createSentryLoggerHandler = (dsn) => {
|
|
43
|
+
const createSentryLoggerHandler = (dsn, options = {}) => {
|
|
71
44
|
if (!dsn) {
|
|
72
45
|
return null;
|
|
73
46
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
47
|
+
let client;
|
|
48
|
+
try {
|
|
49
|
+
client = sentryClient.createSentryClient({
|
|
50
|
+
dsn,
|
|
51
|
+
release: process.env.SENTRY_RELEASE || void 0,
|
|
52
|
+
environment: process.env.SENTRY_ENVIRONMENT || void 0,
|
|
53
|
+
serverName: process.env.SENTRY_NAME || void 0,
|
|
54
|
+
version: options.version
|
|
55
|
+
});
|
|
56
|
+
} catch (error) {
|
|
57
|
+
console.error(`${error instanceof Error ? error.message : String(error)}; errors are not reported to Sentry`);
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
sentryClient.installProcessHandlers(client);
|
|
61
|
+
return new SentryLoggerHandler(logger.LogLevels.warn, client);
|
|
79
62
|
};
|
|
80
63
|
exports.SentryLoggerHandler = SentryLoggerHandler;
|
|
81
64
|
exports.createSentryLoggerHandler = createSentryLoggerHandler;
|
|
82
|
-
exports.filterSentryIntegrations = filterSentryIntegrations;
|
|
83
65
|
//# sourceMappingURL=sentry.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sentry.cjs","sources":["../../../../../packages/engine-http/src/utils/sentry.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"sentry.cjs","sources":["../../../../../packages/engine-http/src/utils/sentry.ts"],"sourcesContent":["import { LogEntry, LoggerHandler, LogLevel, LogLevelName, LogLevels } from '@contember/logger'\nimport { createSentryClient, installProcessHandlers, SentryClient, SeverityLevel } from '@contember/sentry-client'\nimport { LoggerRequestBody } from '../application/index.js'\n\nconst logLevelMapping: Record<LogLevelName, SeverityLevel> = {\n\tcrit: 'fatal',\n\terror: 'error',\n\twarn: 'warning',\n\tdebug: 'debug',\n\tinfo: 'info',\n}\n\nconst stringAttribute = (value: unknown): string | undefined => typeof value === 'string' ? value : undefined\n\nexport class SentryLoggerHandler implements LoggerHandler {\n\tconstructor(\n\t\tprivate readonly logLevel: LogLevel,\n\t\tprivate readonly client: SentryClient,\n\t) {\n\t}\n\n\tgetMinLevel(): number {\n\t\treturn this.logLevel.value\n\t}\n\n\thandle(entry: LogEntry) {\n\t\tif (!entry.error || entry.level.value < this.logLevel.value) {\n\t\t\treturn\n\t\t}\n\t\tconst attribute = (name: string): string | undefined => stringAttribute(entry.loggerAttributes[name] ?? entry.ownAttributes[name])\n\t\tconst traceId = stringAttribute(entry.loggerAttributes.traceId)\n\t\tconst spanId = stringAttribute(entry.loggerAttributes.spanId)\n\t\tthis.client.captureException(entry.error, {\n\t\t\tlevel: logLevelMapping[entry.level.name],\n\t\t\ttags: { project: attribute('project'), projectGroup: attribute('projectGroup'), module: attribute('module') },\n\t\t\tuser: { id: attribute('user') },\n\t\t\textra: { requestId: entry.loggerAttributes.requestId },\n\t\t\t// the request logger sets `uri`, already masked by maskRequestUri\n\t\t\trequest: { url: attribute('uri'), data: entry.loggerAttributes[LoggerRequestBody] },\n\t\t\t...(traceId !== undefined && spanId !== undefined ? { contexts: { trace: { trace_id: traceId, span_id: spanId } } } : {}),\n\t\t})\n\t}\n\n\tclose(): void {\n\t}\n}\n\nexport interface SentryLoggerHandlerOptions {\n\t/** Reported as the SDK version; the client is released together with the server, so this is the server version. */\n\treadonly version?: string\n}\n\n/**\n * Reports logged errors (warn and up) and uncaught exceptions and unhandled rejections of the process.\n * Release, environment and server name come from SENTRY_RELEASE, SENTRY_ENVIRONMENT and SENTRY_NAME (default: the host name). Nothing instruments outgoing requests, whose\n * URLs may carry a webhook credential.\n */\nexport const createSentryLoggerHandler = (dsn?: string, options: SentryLoggerHandlerOptions = {}): null | LoggerHandler => {\n\tif (!dsn) {\n\t\treturn null\n\t}\n\tlet client: SentryClient\n\ttry {\n\t\tclient = createSentryClient({\n\t\t\tdsn,\n\t\t\trelease: process.env.SENTRY_RELEASE || undefined,\n\t\t\tenvironment: process.env.SENTRY_ENVIRONMENT || undefined,\n\t\t\tserverName: process.env.SENTRY_NAME || undefined,\n\t\t\tversion: options.version,\n\t\t})\n\t} catch (error) {\n\t\t// as before: an invalid DSN turns reporting off instead of keeping the server from starting\n\t\tconsole.error(`${error instanceof Error ? error.message : String(error)}; errors are not reported to Sentry`)\n\t\treturn null\n\t}\n\tinstallProcessHandlers(client)\n\treturn new SentryLoggerHandler(LogLevels.warn, client)\n}\n"],"names":["LoggerRequestBody","createSentryClient","installProcessHandlers","LogLevels"],"mappings":";;;;;;AAIA,MAAM,kBAAuD;AAAA,EAC5D,MAAM;AAAA,EACN,OAAO;AAAA,EACP,MAAM;AAAA,EACN,OAAO;AAAA,EACP,MAAM;AACP;AAEA,MAAM,kBAAkB,CAAC,UAAuC,OAAO,UAAU,WAAW,QAAQ;AAE7F,MAAM,oBAA6C;AAAA,EACzD,YACkB,UACA,QAChB;AAFgB,SAAA,WAAA;AACA,SAAA,SAAA;AAAA,EAElB;AAAA,EAEA,cAAsB;AACrB,WAAO,KAAK,SAAS;AAAA,EACtB;AAAA,EAEA,OAAO,OAAiB;AACvB,QAAI,CAAC,MAAM,SAAS,MAAM,MAAM,QAAQ,KAAK,SAAS,OAAO;AAC5D;AAAA,IACD;AACA,UAAM,YAAY,CAAC,SAAqC,gBAAgB,MAAM,iBAAiB,IAAI,KAAK,MAAM,cAAc,IAAI,CAAC;AACjI,UAAM,UAAU,gBAAgB,MAAM,iBAAiB,OAAO;AAC9D,UAAM,SAAS,gBAAgB,MAAM,iBAAiB,MAAM;AAC5D,SAAK,OAAO,iBAAiB,MAAM,OAAO;AAAA,MACzC,OAAO,gBAAgB,MAAM,MAAM,IAAI;AAAA,MACvC,MAAM,EAAE,SAAS,UAAU,SAAS,GAAG,cAAc,UAAU,cAAc,GAAG,QAAQ,UAAU,QAAQ,EAAA;AAAA,MAC1G,MAAM,EAAE,IAAI,UAAU,MAAM,EAAA;AAAA,MAC5B,OAAO,EAAE,WAAW,MAAM,iBAAiB,UAAA;AAAA;AAAA,MAE3C,SAAS,EAAE,KAAK,UAAU,KAAK,GAAG,MAAM,MAAM,iBAAiBA,YAAAA,iBAAiB,EAAA;AAAA,MAChF,GAAI,YAAY,UAAa,WAAW,SAAY,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,SAAS,SAAS,SAAO,EAAE,IAAM,CAAA;AAAA,IAAC,CACvH;AAAA,EACF;AAAA,EAEA,QAAc;AAAA,EACd;AACD;AAYO,MAAM,4BAA4B,CAAC,KAAc,UAAsC,OAA6B;AAC1H,MAAI,CAAC,KAAK;AACT,WAAO;AAAA,EACR;AACA,MAAI;AACJ,MAAI;AACH,aAASC,aAAAA,mBAAmB;AAAA,MAC3B;AAAA,MACA,SAAS,QAAQ,IAAI,kBAAkB;AAAA,MACvC,aAAa,QAAQ,IAAI,sBAAsB;AAAA,MAC/C,YAAY,QAAQ,IAAI,eAAe;AAAA,MACvC,SAAS,QAAQ;AAAA,IAAA,CACjB;AAAA,EACF,SAAS,OAAO;AAEf,YAAQ,MAAM,GAAG,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC,qCAAqC;AAC5G,WAAO;AAAA,EACR;AACAC,eAAAA,uBAAuB,MAAM;AAC7B,SAAO,IAAI,oBAAoBC,iBAAU,MAAM,MAAM;AACtD;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as Sentry from "@sentry/node";
|
|
2
1
|
import { LogLevels } from "@contember/logger";
|
|
2
|
+
import { createSentryClient, installProcessHandlers } from "@contember/sentry-client";
|
|
3
3
|
import { LoggerRequestBody } from "../application/application.js";
|
|
4
4
|
import "../application/requestBodyMasking.js";
|
|
5
5
|
const logLevelMapping = {
|
|
@@ -9,9 +9,11 @@ const logLevelMapping = {
|
|
|
9
9
|
debug: "debug",
|
|
10
10
|
info: "info"
|
|
11
11
|
};
|
|
12
|
+
const stringAttribute = (value) => typeof value === "string" ? value : void 0;
|
|
12
13
|
class SentryLoggerHandler {
|
|
13
|
-
constructor(logLevel) {
|
|
14
|
+
constructor(logLevel, client) {
|
|
14
15
|
this.logLevel = logLevel;
|
|
16
|
+
this.client = client;
|
|
15
17
|
}
|
|
16
18
|
getMinLevel() {
|
|
17
19
|
return this.logLevel.value;
|
|
@@ -20,47 +22,44 @@ class SentryLoggerHandler {
|
|
|
20
22
|
if (!entry.error || entry.level.value < this.logLevel.value) {
|
|
21
23
|
return;
|
|
22
24
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const spanId = entry.loggerAttributes.spanId;
|
|
35
|
-
return {
|
|
36
|
-
...event,
|
|
37
|
-
request: {
|
|
38
|
-
url: entry.loggerAttributes.url ?? entry.ownAttributes.url,
|
|
39
|
-
data: entry.loggerAttributes[LoggerRequestBody]
|
|
40
|
-
},
|
|
41
|
-
...typeof traceId === "string" && typeof spanId === "string" ? { contexts: { ...event.contexts, trace: { trace_id: traceId, span_id: spanId } } } : {}
|
|
42
|
-
};
|
|
43
|
-
});
|
|
44
|
-
return scope;
|
|
25
|
+
const attribute = (name) => stringAttribute(entry.loggerAttributes[name] ?? entry.ownAttributes[name]);
|
|
26
|
+
const traceId = stringAttribute(entry.loggerAttributes.traceId);
|
|
27
|
+
const spanId = stringAttribute(entry.loggerAttributes.spanId);
|
|
28
|
+
this.client.captureException(entry.error, {
|
|
29
|
+
level: logLevelMapping[entry.level.name],
|
|
30
|
+
tags: { project: attribute("project"), projectGroup: attribute("projectGroup"), module: attribute("module") },
|
|
31
|
+
user: { id: attribute("user") },
|
|
32
|
+
extra: { requestId: entry.loggerAttributes.requestId },
|
|
33
|
+
// the request logger sets `uri`, already masked by maskRequestUri
|
|
34
|
+
request: { url: attribute("uri"), data: entry.loggerAttributes[LoggerRequestBody] },
|
|
35
|
+
...traceId !== void 0 && spanId !== void 0 ? { contexts: { trace: { trace_id: traceId, span_id: spanId } } } : {}
|
|
45
36
|
});
|
|
46
37
|
}
|
|
47
38
|
close() {
|
|
48
39
|
}
|
|
49
40
|
}
|
|
50
|
-
const
|
|
51
|
-
const createSentryLoggerHandler = (dsn) => {
|
|
41
|
+
const createSentryLoggerHandler = (dsn, options = {}) => {
|
|
52
42
|
if (!dsn) {
|
|
53
43
|
return null;
|
|
54
44
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
45
|
+
let client;
|
|
46
|
+
try {
|
|
47
|
+
client = createSentryClient({
|
|
48
|
+
dsn,
|
|
49
|
+
release: process.env.SENTRY_RELEASE || void 0,
|
|
50
|
+
environment: process.env.SENTRY_ENVIRONMENT || void 0,
|
|
51
|
+
serverName: process.env.SENTRY_NAME || void 0,
|
|
52
|
+
version: options.version
|
|
53
|
+
});
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.error(`${error instanceof Error ? error.message : String(error)}; errors are not reported to Sentry`);
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
installProcessHandlers(client);
|
|
59
|
+
return new SentryLoggerHandler(LogLevels.warn, client);
|
|
60
60
|
};
|
|
61
61
|
export {
|
|
62
62
|
SentryLoggerHandler,
|
|
63
|
-
createSentryLoggerHandler
|
|
64
|
-
filterSentryIntegrations
|
|
63
|
+
createSentryLoggerHandler
|
|
65
64
|
};
|
|
66
65
|
//# sourceMappingURL=sentry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sentry.js","sources":["../../../../../packages/engine-http/src/utils/sentry.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"sentry.js","sources":["../../../../../packages/engine-http/src/utils/sentry.ts"],"sourcesContent":["import { LogEntry, LoggerHandler, LogLevel, LogLevelName, LogLevels } from '@contember/logger'\nimport { createSentryClient, installProcessHandlers, SentryClient, SeverityLevel } from '@contember/sentry-client'\nimport { LoggerRequestBody } from '../application/index.js'\n\nconst logLevelMapping: Record<LogLevelName, SeverityLevel> = {\n\tcrit: 'fatal',\n\terror: 'error',\n\twarn: 'warning',\n\tdebug: 'debug',\n\tinfo: 'info',\n}\n\nconst stringAttribute = (value: unknown): string | undefined => typeof value === 'string' ? value : undefined\n\nexport class SentryLoggerHandler implements LoggerHandler {\n\tconstructor(\n\t\tprivate readonly logLevel: LogLevel,\n\t\tprivate readonly client: SentryClient,\n\t) {\n\t}\n\n\tgetMinLevel(): number {\n\t\treturn this.logLevel.value\n\t}\n\n\thandle(entry: LogEntry) {\n\t\tif (!entry.error || entry.level.value < this.logLevel.value) {\n\t\t\treturn\n\t\t}\n\t\tconst attribute = (name: string): string | undefined => stringAttribute(entry.loggerAttributes[name] ?? entry.ownAttributes[name])\n\t\tconst traceId = stringAttribute(entry.loggerAttributes.traceId)\n\t\tconst spanId = stringAttribute(entry.loggerAttributes.spanId)\n\t\tthis.client.captureException(entry.error, {\n\t\t\tlevel: logLevelMapping[entry.level.name],\n\t\t\ttags: { project: attribute('project'), projectGroup: attribute('projectGroup'), module: attribute('module') },\n\t\t\tuser: { id: attribute('user') },\n\t\t\textra: { requestId: entry.loggerAttributes.requestId },\n\t\t\t// the request logger sets `uri`, already masked by maskRequestUri\n\t\t\trequest: { url: attribute('uri'), data: entry.loggerAttributes[LoggerRequestBody] },\n\t\t\t...(traceId !== undefined && spanId !== undefined ? { contexts: { trace: { trace_id: traceId, span_id: spanId } } } : {}),\n\t\t})\n\t}\n\n\tclose(): void {\n\t}\n}\n\nexport interface SentryLoggerHandlerOptions {\n\t/** Reported as the SDK version; the client is released together with the server, so this is the server version. */\n\treadonly version?: string\n}\n\n/**\n * Reports logged errors (warn and up) and uncaught exceptions and unhandled rejections of the process.\n * Release, environment and server name come from SENTRY_RELEASE, SENTRY_ENVIRONMENT and SENTRY_NAME (default: the host name). Nothing instruments outgoing requests, whose\n * URLs may carry a webhook credential.\n */\nexport const createSentryLoggerHandler = (dsn?: string, options: SentryLoggerHandlerOptions = {}): null | LoggerHandler => {\n\tif (!dsn) {\n\t\treturn null\n\t}\n\tlet client: SentryClient\n\ttry {\n\t\tclient = createSentryClient({\n\t\t\tdsn,\n\t\t\trelease: process.env.SENTRY_RELEASE || undefined,\n\t\t\tenvironment: process.env.SENTRY_ENVIRONMENT || undefined,\n\t\t\tserverName: process.env.SENTRY_NAME || undefined,\n\t\t\tversion: options.version,\n\t\t})\n\t} catch (error) {\n\t\t// as before: an invalid DSN turns reporting off instead of keeping the server from starting\n\t\tconsole.error(`${error instanceof Error ? error.message : String(error)}; errors are not reported to Sentry`)\n\t\treturn null\n\t}\n\tinstallProcessHandlers(client)\n\treturn new SentryLoggerHandler(LogLevels.warn, client)\n}\n"],"names":[],"mappings":";;;;AAIA,MAAM,kBAAuD;AAAA,EAC5D,MAAM;AAAA,EACN,OAAO;AAAA,EACP,MAAM;AAAA,EACN,OAAO;AAAA,EACP,MAAM;AACP;AAEA,MAAM,kBAAkB,CAAC,UAAuC,OAAO,UAAU,WAAW,QAAQ;AAE7F,MAAM,oBAA6C;AAAA,EACzD,YACkB,UACA,QAChB;AAFgB,SAAA,WAAA;AACA,SAAA,SAAA;AAAA,EAElB;AAAA,EAEA,cAAsB;AACrB,WAAO,KAAK,SAAS;AAAA,EACtB;AAAA,EAEA,OAAO,OAAiB;AACvB,QAAI,CAAC,MAAM,SAAS,MAAM,MAAM,QAAQ,KAAK,SAAS,OAAO;AAC5D;AAAA,IACD;AACA,UAAM,YAAY,CAAC,SAAqC,gBAAgB,MAAM,iBAAiB,IAAI,KAAK,MAAM,cAAc,IAAI,CAAC;AACjI,UAAM,UAAU,gBAAgB,MAAM,iBAAiB,OAAO;AAC9D,UAAM,SAAS,gBAAgB,MAAM,iBAAiB,MAAM;AAC5D,SAAK,OAAO,iBAAiB,MAAM,OAAO;AAAA,MACzC,OAAO,gBAAgB,MAAM,MAAM,IAAI;AAAA,MACvC,MAAM,EAAE,SAAS,UAAU,SAAS,GAAG,cAAc,UAAU,cAAc,GAAG,QAAQ,UAAU,QAAQ,EAAA;AAAA,MAC1G,MAAM,EAAE,IAAI,UAAU,MAAM,EAAA;AAAA,MAC5B,OAAO,EAAE,WAAW,MAAM,iBAAiB,UAAA;AAAA;AAAA,MAE3C,SAAS,EAAE,KAAK,UAAU,KAAK,GAAG,MAAM,MAAM,iBAAiB,iBAAiB,EAAA;AAAA,MAChF,GAAI,YAAY,UAAa,WAAW,SAAY,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,SAAS,SAAS,SAAO,EAAE,IAAM,CAAA;AAAA,IAAC,CACvH;AAAA,EACF;AAAA,EAEA,QAAc;AAAA,EACd;AACD;AAYO,MAAM,4BAA4B,CAAC,KAAc,UAAsC,OAA6B;AAC1H,MAAI,CAAC,KAAK;AACT,WAAO;AAAA,EACR;AACA,MAAI;AACJ,MAAI;AACH,aAAS,mBAAmB;AAAA,MAC3B;AAAA,MACA,SAAS,QAAQ,IAAI,kBAAkB;AAAA,MACvC,aAAa,QAAQ,IAAI,sBAAsB;AAAA,MAC/C,YAAY,QAAQ,IAAI,eAAe;AAAA,MACvC,SAAS,QAAQ;AAAA,IAAA,CACjB;AAAA,EACF,SAAS,OAAO;AAEf,YAAQ,MAAM,GAAG,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC,qCAAqC;AAC5G,WAAO;AAAA,EACR;AACA,yBAAuB,MAAM;AAC7B,SAAO,IAAI,oBAAoB,UAAU,MAAM,MAAM;AACtD;"}
|
|
@@ -37,11 +37,13 @@ const createDefaultLogger = () => {
|
|
|
37
37
|
formatters: {
|
|
38
38
|
pid: () => void 0,
|
|
39
39
|
loggerId: () => void 0,
|
|
40
|
-
uri: ({ attributes,
|
|
41
|
-
const color = attributes.status === void 0 ?
|
|
40
|
+
uri: ({ attributes, style }) => {
|
|
41
|
+
const color = attributes.status === void 0 ? "cyan" : attributes.status < 300 ? "green" : "yellowBright";
|
|
42
42
|
const timeInfo = attributes.totalTimeMs !== void 0 ? ` ${attributes.totalTimeMs}ms` : "";
|
|
43
43
|
const statusInfo = attributes.status !== void 0 ? ` [${attributes.status}]` : "";
|
|
44
|
-
return {
|
|
44
|
+
return {
|
|
45
|
+
line: style(color, `${attributes.method}${statusInfo} ${attributes.uri}${timeInfo} ${style(["white", "dim"], "#" + attributes.requestId)}`)
|
|
46
|
+
};
|
|
45
47
|
},
|
|
46
48
|
method: () => void 0,
|
|
47
49
|
requestId: () => void 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serverStartup.cjs","sources":["../../../../../packages/engine-http/src/utils/serverStartup.ts"],"sourcesContent":["import { join } from 'node:path'\nimport { ConfigSource, readConfig, ServerConfig } from '../config/config.js'\nimport { Type } from '@contember/typesafe'\nimport { createLogger, JsonStreamLoggerHandler, Logger, LogLevels, PrettyPrintLoggerHandler } from '@contember/logger'\nimport { ConfigProcessor } from '../config/ConfigProcessor.js'\nimport { Plugin } from '../plugin/Plugin.js'\nimport { readFile } from 'node:fs/promises'\n\nexport const getServerVersion = async (): Promise<string> => {\n\tconst packageJsonFile = process.env.CONTEMBER_PACKAGE_JSON || join(process.cwd(), 'package.json')\n\tconst version = JSON.parse(await readFile(packageJsonFile, 'utf-8')).version\n\treturn version\n}\n\nexport const isDebugMode = (): boolean => process.env.NODE_ENV === 'development'\n\nexport const printStartInfo = ({ version, isDebug }: { version: string; isDebug: boolean }, logger: Logger) => {\n\tlogger.info(`Starting Contember ${version}`)\n\tlogger.info(`NODE_ENV is set to ${process.env.NODE_ENV}`)\n\tif (isDebug) {\n\t\tlogger.warn('Starting Contember in debug mode')\n\t\tlogger.warn('NEVER USE debug mode in production environment')\n\t}\n}\n\nexport const resolveServerConfig = async <T extends ServerConfig>(\n\t{ plugins, serverConfigSchema }: { plugins: Plugin[]; serverConfigSchema: Type<T> },\n) => {\n\tconst configProcessors = plugins\n\t\t.map(it => (it.getConfigProcessor ? it.getConfigProcessor() : null))\n\t\t.filter((it): it is ConfigProcessor<any> => it !== null)\n\n\tconst configSources: ConfigSource[] = []\n\tfor (const configType of ['file', 'yaml', 'json'] as const) {\n\t\tconst envValue = process.env['CONTEMBER_CONFIG_' + configType.toUpperCase()]\n\t\tif (envValue) {\n\t\t\tconfigSources.push({ type: configType, data: envValue })\n\t\t}\n\t}\n\n\treturn await readConfig(configSources, configProcessors, serverConfigSchema)\n}\n\nexport const createDefaultLogger = (): Logger => {\n\tconst isDebug = isDebugMode()\n\tconst loggerType = process.env.CONTEMBER_LOGGER_FORMAT ?? (isDebug ? 'pretty' : 'json')\n\tconst stream = process.stderr\n\tconst handler = loggerType === 'pretty'\n\t\t? new PrettyPrintLoggerHandler(stream, {\n\t\t\tformatters: {\n\t\t\t\tpid: () => undefined,\n\t\t\t\tloggerId: () => undefined,\n\t\t\t\turi: ({ attributes,
|
|
1
|
+
{"version":3,"file":"serverStartup.cjs","sources":["../../../../../packages/engine-http/src/utils/serverStartup.ts"],"sourcesContent":["import { join } from 'node:path'\nimport { ConfigSource, readConfig, ServerConfig } from '../config/config.js'\nimport { Type } from '@contember/typesafe'\nimport { createLogger, JsonStreamLoggerHandler, Logger, LogLevels, PrettyPrintLoggerHandler } from '@contember/logger'\nimport { ConfigProcessor } from '../config/ConfigProcessor.js'\nimport { Plugin } from '../plugin/Plugin.js'\nimport { readFile } from 'node:fs/promises'\n\nexport const getServerVersion = async (): Promise<string> => {\n\tconst packageJsonFile = process.env.CONTEMBER_PACKAGE_JSON || join(process.cwd(), 'package.json')\n\tconst version = JSON.parse(await readFile(packageJsonFile, 'utf-8')).version\n\treturn version\n}\n\nexport const isDebugMode = (): boolean => process.env.NODE_ENV === 'development'\n\nexport const printStartInfo = ({ version, isDebug }: { version: string; isDebug: boolean }, logger: Logger) => {\n\tlogger.info(`Starting Contember ${version}`)\n\tlogger.info(`NODE_ENV is set to ${process.env.NODE_ENV}`)\n\tif (isDebug) {\n\t\tlogger.warn('Starting Contember in debug mode')\n\t\tlogger.warn('NEVER USE debug mode in production environment')\n\t}\n}\n\nexport const resolveServerConfig = async <T extends ServerConfig>(\n\t{ plugins, serverConfigSchema }: { plugins: Plugin[]; serverConfigSchema: Type<T> },\n) => {\n\tconst configProcessors = plugins\n\t\t.map(it => (it.getConfigProcessor ? it.getConfigProcessor() : null))\n\t\t.filter((it): it is ConfigProcessor<any> => it !== null)\n\n\tconst configSources: ConfigSource[] = []\n\tfor (const configType of ['file', 'yaml', 'json'] as const) {\n\t\tconst envValue = process.env['CONTEMBER_CONFIG_' + configType.toUpperCase()]\n\t\tif (envValue) {\n\t\t\tconfigSources.push({ type: configType, data: envValue })\n\t\t}\n\t}\n\n\treturn await readConfig(configSources, configProcessors, serverConfigSchema)\n}\n\nexport const createDefaultLogger = (): Logger => {\n\tconst isDebug = isDebugMode()\n\tconst loggerType = process.env.CONTEMBER_LOGGER_FORMAT ?? (isDebug ? 'pretty' : 'json')\n\tconst stream = process.stderr\n\tconst handler = loggerType === 'pretty'\n\t\t? new PrettyPrintLoggerHandler(stream, {\n\t\t\tformatters: {\n\t\t\t\tpid: () => undefined,\n\t\t\t\tloggerId: () => undefined,\n\t\t\t\turi: ({ attributes, style }) => {\n\t\t\t\t\tconst color = attributes.status === undefined\n\t\t\t\t\t\t? 'cyan'\n\t\t\t\t\t\t: attributes.status < 300\n\t\t\t\t\t\t? 'green'\n\t\t\t\t\t\t: 'yellowBright'\n\t\t\t\t\tconst timeInfo = attributes.totalTimeMs !== undefined ? ` ${attributes.totalTimeMs}ms` : ''\n\t\t\t\t\tconst statusInfo = attributes.status !== undefined ? ` [${attributes.status}]` : ''\n\t\t\t\t\treturn {\n\t\t\t\t\t\tline: style(color, `${attributes.method}${statusInfo} ${attributes.uri}${timeInfo} ${style(['white', 'dim'], '#' + attributes.requestId)}`),\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tmethod: () => undefined,\n\t\t\t\trequestId: () => undefined,\n\t\t\t\ttimeLabel: () => undefined,\n\t\t\t\tstatus: () => undefined,\n\t\t\t\ttotalTimeMs: () => undefined,\n\t\t\t\tevents: ({ formattedValue }) => formattedValue === '[]' ? undefined : formattedValue,\n\t\t\t},\n\t\t})\n\t\t: new JsonStreamLoggerHandler(stream)\n\tconst logLevel = (process.env.CONTEMBER_LOGGER_LEVEL as keyof typeof LogLevels) ?? 'info'\n\treturn createLogger(handler, {\n\t\tpid: process.pid,\n\t\tloggerId: Math.random().toString().substring(2),\n\t}, {\n\t\tfingerCrossedOptions: {\n\t\t\tlogAlwaysLevel: LogLevels[logLevel],\n\t\t},\n\t})\n}\n"],"names":["join","readFile","logger","readConfig","PrettyPrintLoggerHandler","JsonStreamLoggerHandler","createLogger","LogLevels"],"mappings":";;;;;;AAQO,MAAM,mBAAmB,YAA6B;AAC5D,QAAM,kBAAkB,QAAQ,IAAI,0BAA0BA,KAAAA,KAAK,QAAQ,IAAA,GAAO,cAAc;AAChG,QAAM,UAAU,KAAK,MAAM,MAAMC,GAAAA,SAAS,iBAAiB,OAAO,CAAC,EAAE;AACrE,SAAO;AACR;AAEO,MAAM,cAAc,MAAe,QAAQ,IAAI,aAAa;AAE5D,MAAM,iBAAiB,CAAC,EAAE,SAAS,QAAA,GAAkDC,YAAmB;AAC9G,EAAAA,QAAO,KAAK,sBAAsB,OAAO,EAAE;AAC3C,EAAAA,QAAO,KAAK,sBAAsB,QAAQ,IAAI,QAAQ,EAAE;AACxD,MAAI,SAAS;AACZ,IAAAA,QAAO,KAAK,kCAAkC;AAC9C,IAAAA,QAAO,KAAK,gDAAgD;AAAA,EAC7D;AACD;AAEO,MAAM,sBAAsB,OAClC,EAAE,SAAS,yBACP;AACJ,QAAM,mBAAmB,QACvB,IAAI,CAAA,OAAO,GAAG,qBAAqB,GAAG,mBAAA,IAAuB,IAAK,EAClE,OAAO,CAAC,OAAmC,OAAO,IAAI;AAExD,QAAM,gBAAgC,CAAA;AACtC,aAAW,cAAc,CAAC,QAAQ,QAAQ,MAAM,GAAY;AAC3D,UAAM,WAAW,QAAQ,IAAI,sBAAsB,WAAW,aAAa;AAC3E,QAAI,UAA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AAA,IACF,sBAAsB;AAAA,MACrB,gBAAgBC,OAAAA,UAAU,QAAQ;AAAA,IAAA;AAAA,EACnC,CACA;AACF;;;;;;"}
|
|
@@ -35,11 +35,13 @@ const createDefaultLogger = () => {
|
|
|
35
35
|
formatters: {
|
|
36
36
|
pid: () => void 0,
|
|
37
37
|
loggerId: () => void 0,
|
|
38
|
-
uri: ({ attributes,
|
|
39
|
-
const color = attributes.status === void 0 ?
|
|
38
|
+
uri: ({ attributes, style }) => {
|
|
39
|
+
const color = attributes.status === void 0 ? "cyan" : attributes.status < 300 ? "green" : "yellowBright";
|
|
40
40
|
const timeInfo = attributes.totalTimeMs !== void 0 ? ` ${attributes.totalTimeMs}ms` : "";
|
|
41
41
|
const statusInfo = attributes.status !== void 0 ? ` [${attributes.status}]` : "";
|
|
42
|
-
return {
|
|
42
|
+
return {
|
|
43
|
+
line: style(color, `${attributes.method}${statusInfo} ${attributes.uri}${timeInfo} ${style(["white", "dim"], "#" + attributes.requestId)}`)
|
|
44
|
+
};
|
|
43
45
|
},
|
|
44
46
|
method: () => void 0,
|
|
45
47
|
requestId: () => void 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serverStartup.js","sources":["../../../../../packages/engine-http/src/utils/serverStartup.ts"],"sourcesContent":["import { join } from 'node:path'\nimport { ConfigSource, readConfig, ServerConfig } from '../config/config.js'\nimport { Type } from '@contember/typesafe'\nimport { createLogger, JsonStreamLoggerHandler, Logger, LogLevels, PrettyPrintLoggerHandler } from '@contember/logger'\nimport { ConfigProcessor } from '../config/ConfigProcessor.js'\nimport { Plugin } from '../plugin/Plugin.js'\nimport { readFile } from 'node:fs/promises'\n\nexport const getServerVersion = async (): Promise<string> => {\n\tconst packageJsonFile = process.env.CONTEMBER_PACKAGE_JSON || join(process.cwd(), 'package.json')\n\tconst version = JSON.parse(await readFile(packageJsonFile, 'utf-8')).version\n\treturn version\n}\n\nexport const isDebugMode = (): boolean => process.env.NODE_ENV === 'development'\n\nexport const printStartInfo = ({ version, isDebug }: { version: string; isDebug: boolean }, logger: Logger) => {\n\tlogger.info(`Starting Contember ${version}`)\n\tlogger.info(`NODE_ENV is set to ${process.env.NODE_ENV}`)\n\tif (isDebug) {\n\t\tlogger.warn('Starting Contember in debug mode')\n\t\tlogger.warn('NEVER USE debug mode in production environment')\n\t}\n}\n\nexport const resolveServerConfig = async <T extends ServerConfig>(\n\t{ plugins, serverConfigSchema }: { plugins: Plugin[]; serverConfigSchema: Type<T> },\n) => {\n\tconst configProcessors = plugins\n\t\t.map(it => (it.getConfigProcessor ? it.getConfigProcessor() : null))\n\t\t.filter((it): it is ConfigProcessor<any> => it !== null)\n\n\tconst configSources: ConfigSource[] = []\n\tfor (const configType of ['file', 'yaml', 'json'] as const) {\n\t\tconst envValue = process.env['CONTEMBER_CONFIG_' + configType.toUpperCase()]\n\t\tif (envValue) {\n\t\t\tconfigSources.push({ type: configType, data: envValue })\n\t\t}\n\t}\n\n\treturn await readConfig(configSources, configProcessors, serverConfigSchema)\n}\n\nexport const createDefaultLogger = (): Logger => {\n\tconst isDebug = isDebugMode()\n\tconst loggerType = process.env.CONTEMBER_LOGGER_FORMAT ?? (isDebug ? 'pretty' : 'json')\n\tconst stream = process.stderr\n\tconst handler = loggerType === 'pretty'\n\t\t? new PrettyPrintLoggerHandler(stream, {\n\t\t\tformatters: {\n\t\t\t\tpid: () => undefined,\n\t\t\t\tloggerId: () => undefined,\n\t\t\t\turi: ({ attributes,
|
|
1
|
+
{"version":3,"file":"serverStartup.js","sources":["../../../../../packages/engine-http/src/utils/serverStartup.ts"],"sourcesContent":["import { join } from 'node:path'\nimport { ConfigSource, readConfig, ServerConfig } from '../config/config.js'\nimport { Type } from '@contember/typesafe'\nimport { createLogger, JsonStreamLoggerHandler, Logger, LogLevels, PrettyPrintLoggerHandler } from '@contember/logger'\nimport { ConfigProcessor } from '../config/ConfigProcessor.js'\nimport { Plugin } from '../plugin/Plugin.js'\nimport { readFile } from 'node:fs/promises'\n\nexport const getServerVersion = async (): Promise<string> => {\n\tconst packageJsonFile = process.env.CONTEMBER_PACKAGE_JSON || join(process.cwd(), 'package.json')\n\tconst version = JSON.parse(await readFile(packageJsonFile, 'utf-8')).version\n\treturn version\n}\n\nexport const isDebugMode = (): boolean => process.env.NODE_ENV === 'development'\n\nexport const printStartInfo = ({ version, isDebug }: { version: string; isDebug: boolean }, logger: Logger) => {\n\tlogger.info(`Starting Contember ${version}`)\n\tlogger.info(`NODE_ENV is set to ${process.env.NODE_ENV}`)\n\tif (isDebug) {\n\t\tlogger.warn('Starting Contember in debug mode')\n\t\tlogger.warn('NEVER USE debug mode in production environment')\n\t}\n}\n\nexport const resolveServerConfig = async <T extends ServerConfig>(\n\t{ plugins, serverConfigSchema }: { plugins: Plugin[]; serverConfigSchema: Type<T> },\n) => {\n\tconst configProcessors = plugins\n\t\t.map(it => (it.getConfigProcessor ? it.getConfigProcessor() : null))\n\t\t.filter((it): it is ConfigProcessor<any> => it !== null)\n\n\tconst configSources: ConfigSource[] = []\n\tfor (const configType of ['file', 'yaml', 'json'] as const) {\n\t\tconst envValue = process.env['CONTEMBER_CONFIG_' + configType.toUpperCase()]\n\t\tif (envValue) {\n\t\t\tconfigSources.push({ type: configType, data: envValue })\n\t\t}\n\t}\n\n\treturn await readConfig(configSources, configProcessors, serverConfigSchema)\n}\n\nexport const createDefaultLogger = (): Logger => {\n\tconst isDebug = isDebugMode()\n\tconst loggerType = process.env.CONTEMBER_LOGGER_FORMAT ?? (isDebug ? 'pretty' : 'json')\n\tconst stream = process.stderr\n\tconst handler = loggerType === 'pretty'\n\t\t? new PrettyPrintLoggerHandler(stream, {\n\t\t\tformatters: {\n\t\t\t\tpid: () => undefined,\n\t\t\t\tloggerId: () => undefined,\n\t\t\t\turi: ({ attributes, style }) => {\n\t\t\t\t\tconst color = attributes.status === undefined\n\t\t\t\t\t\t? 'cyan'\n\t\t\t\t\t\t: attributes.status < 300\n\t\t\t\t\t\t? 'green'\n\t\t\t\t\t\t: 'yellowBright'\n\t\t\t\t\tconst timeInfo = attributes.totalTimeMs !== undefined ? ` ${attributes.totalTimeMs}ms` : ''\n\t\t\t\t\tconst statusInfo = attributes.status !== undefined ? ` [${attributes.status}]` : ''\n\t\t\t\t\treturn {\n\t\t\t\t\t\tline: style(color, `${attributes.method}${statusInfo} ${attributes.uri}${timeInfo} ${style(['white', 'dim'], '#' + attributes.requestId)}`),\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tmethod: () => undefined,\n\t\t\t\trequestId: () => undefined,\n\t\t\t\ttimeLabel: () => undefined,\n\t\t\t\tstatus: () => undefined,\n\t\t\t\ttotalTimeMs: () => undefined,\n\t\t\t\tevents: ({ formattedValue }) => formattedValue === '[]' ? undefined : formattedValue,\n\t\t\t},\n\t\t})\n\t\t: new JsonStreamLoggerHandler(stream)\n\tconst logLevel = (process.env.CONTEMBER_LOGGER_LEVEL as keyof typeof LogLevels) ?? 'info'\n\treturn createLogger(handler, {\n\t\tpid: process.pid,\n\t\tloggerId: Math.random().toString().substring(2),\n\t}, {\n\t\tfingerCrossedOptions: {\n\t\t\tlogAlwaysLevel: LogLevels[logLevel],\n\t\t},\n\t})\n}\n"],"names":[],"mappings":";;;;AAQO,MAAM,mBAAmB,YAA6B;AAC5D,QAAM,kBAAkB,QAAQ,IAAI,0BAA0B,KAAK,QAAQ,IAAA,GAAO,cAAc;AAChG,QAAM,UAAU,KAAK,MAAM,MAAM,SAAS,iBAAiB,OAAO,CAAC,EAAE;AACrE,SAAO;AACR;AAEO,MAAM,cAAc,MAAe,QAAQ,IAAI,aAAa;AAE5D,MAAM,iBAAiB,CAAC,EAAE,SAAS,QAAA,GAAkD,WAAmB;AAC9G,SAAO,KAAK,sBAAsB,OAAO,EAAE;AAC3C,SAAO,KAAK,sBAAsB,QAAQ,IAAI,QAAQ,EAAE;AACxD,MAAI,SAAS;AACZ,WAAO,KAAK,kCAAkC;AAC9C,WAAO,KAAK,gDAAgD;AAAA,EAC7D;AACD;AAEO,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B,QAAQ,CAAC,EAAE,qBAAqB,mBAAmB,OAAO,SAAY;AAAA,IAAA;AAAA,EACvE,CACA,IACC,IAAI,wBAAwB,MAAM;AACrC,QAAM,WAAY,QAAQ,IAAI,0BAAqD;AACnF,SAAO,aAAa,SAAS;AAAA,IAC5B,KAAK,QAAQ;AAAA,IACb,UAAU,KAAK,OAAA,EAAS,SAAA,EAAW,UAAU,CAAC;AAAA,EAAA,GAC5C;AAAA,IACF,sBAAsB;AAAA,MACrB,gBAAgB,UAAU,QAAQ;AAAA,IAAA;AAAA,EACnC,CACA;AACF;"}
|
|
@@ -126,7 +126,6 @@ exports.executeTerminationJobs = serverTermination.executeTerminationJobs;
|
|
|
126
126
|
exports.listenOnProcessTermination = serverTermination.listenOnProcessTermination;
|
|
127
127
|
exports.SentryLoggerHandler = sentry.SentryLoggerHandler;
|
|
128
128
|
exports.createSentryLoggerHandler = sentry.createSentryLoggerHandler;
|
|
129
|
-
exports.filterSentryIntegrations = sentry.filterSentryIntegrations;
|
|
130
129
|
exports.createFastSqlSpanFilter = FilteringSpanProcessor.createFastSqlSpanFilter;
|
|
131
130
|
exports.createFilteringSpanProcessor = FilteringSpanProcessor.createFilteringSpanProcessor;
|
|
132
131
|
exports.isIncomingTraceTrusted = incomingTrace.isIncomingTraceTrusted;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../../packages/engine-http/src/index.ts"],"sourcesContent":["import { MasterContainerArgs, MasterContainerFactory } from './MasterContainer.js'\nimport Koa from 'koa'\n\nexport * from './config/config.js'\nexport * from './config/ConfigProcessor.js'\nexport { projectNameToEnvName } from './config/projectConfigResolver.js'\nexport * from './config/tenantConfigResolver.js'\nexport * from './common/index.js'\nexport * from './content/index.js'\nexport * from './plugin/Plugin.js'\nexport * from './misc/index.js'\nexport * from './project-common/index.js'\nexport * from './system/index.js'\nexport * from './tenant/index.js'\nexport * from './transfer/index.js'\nexport * from './application/index.js'\nexport * from './providers.js'\nexport * from './graphql/index.js'\nexport * from './project/config.js'\nexport * from './utils/CryptoWrapper.js'\nexport * from './project/ProjectContainer.js'\nexport * from './project/ProjectContainerResolver.js'\nexport * from './projectGroup/ProjectGroupContainer.js'\nexport * from './projectGroup/ProjectGroupResolver.js'\nexport type { ProjectGroupContainerResolver } from './projectGroup/ProjectGroupContainerResolver.js'\n\nexport * from './testing/index.js'\nexport * from './utils/serverStartup.js'\nexport * from './utils/serverTermination.js'\nexport * from './utils/sentry.js'\nexport * from './telemetry/index.js'\nexport * from './MasterContainer.js'\nexport { serverConfigSchema } from './config/configSchema.js'\n\nexport const createContainer = (args: MasterContainerArgs) => {\n\treturn new MasterContainerFactory().create(args)\n}\n\nexport { Koa }\n"],"names":["MasterContainerFactory"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCO,MAAM,kBAAkB,CAAC,SAA8B;AAC7D,SAAO,IAAIA,gBAAAA,uBAAA,EAAyB,OAAO,IAAI;AAChD
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../packages/engine-http/src/index.ts"],"sourcesContent":["import { MasterContainerArgs, MasterContainerFactory } from './MasterContainer.js'\nimport Koa from 'koa'\n\nexport * from './config/config.js'\nexport * from './config/ConfigProcessor.js'\nexport { projectNameToEnvName } from './config/projectConfigResolver.js'\nexport * from './config/tenantConfigResolver.js'\nexport * from './common/index.js'\nexport * from './content/index.js'\nexport * from './plugin/Plugin.js'\nexport * from './misc/index.js'\nexport * from './project-common/index.js'\nexport * from './system/index.js'\nexport * from './tenant/index.js'\nexport * from './transfer/index.js'\nexport * from './application/index.js'\nexport * from './providers.js'\nexport * from './graphql/index.js'\nexport * from './project/config.js'\nexport * from './utils/CryptoWrapper.js'\nexport * from './project/ProjectContainer.js'\nexport * from './project/ProjectContainerResolver.js'\nexport * from './projectGroup/ProjectGroupContainer.js'\nexport * from './projectGroup/ProjectGroupResolver.js'\nexport type { ProjectGroupContainerResolver } from './projectGroup/ProjectGroupContainerResolver.js'\n\nexport * from './testing/index.js'\nexport * from './utils/serverStartup.js'\nexport * from './utils/serverTermination.js'\nexport * from './utils/sentry.js'\nexport * from './telemetry/index.js'\nexport * from './MasterContainer.js'\nexport { serverConfigSchema } from './config/configSchema.js'\n\nexport const createContainer = (args: MasterContainerArgs) => {\n\treturn new MasterContainerFactory().create(args)\n}\n\nexport { Koa }\n"],"names":["MasterContainerFactory"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCO,MAAM,kBAAkB,CAAC,SAA8B;AAC7D,SAAO,IAAIA,gBAAAA,uBAAA,EAAyB,OAAO,IAAI;AAChD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/production/index.js
CHANGED
|
@@ -44,7 +44,7 @@ import { ProjectGroupResolver } from "./src/projectGroup/ProjectGroupResolver.js
|
|
|
44
44
|
import { TestTransactionService } from "./src/testing/TestTransactions.js";
|
|
45
45
|
import { createDefaultLogger, getServerVersion, isDebugMode, printStartInfo, resolveServerConfig } from "./src/utils/serverStartup.js";
|
|
46
46
|
import { createTerminationExecutor, executeTerminationJobs, listenOnProcessTermination } from "./src/utils/serverTermination.js";
|
|
47
|
-
import { SentryLoggerHandler, createSentryLoggerHandler
|
|
47
|
+
import { SentryLoggerHandler, createSentryLoggerHandler } from "./src/utils/sentry.js";
|
|
48
48
|
import { createFastSqlSpanFilter, createFilteringSpanProcessor } from "./src/telemetry/FilteringSpanProcessor.js";
|
|
49
49
|
import { isIncomingTraceTrusted, resolveIncomingSpanContext } from "./src/telemetry/incomingTrace.js";
|
|
50
50
|
import { ProjectGroupContainerTelemetryHook } from "./src/telemetry/ProjectGroupContainerTelemetryHook.js";
|
|
@@ -114,7 +114,6 @@ export {
|
|
|
114
114
|
defaultServiceName,
|
|
115
115
|
executeTerminationJobs,
|
|
116
116
|
extractOriginalError,
|
|
117
|
-
filterSentryIntegrations,
|
|
118
117
|
forceHttpOkHeader,
|
|
119
118
|
getServerVersion,
|
|
120
119
|
homepageController,
|
|
@@ -8,9 +8,9 @@ const Koa = require("koa");
|
|
|
8
8
|
const http = require("node:http");
|
|
9
9
|
const ws = require("ws");
|
|
10
10
|
const logger = require("@contember/logger");
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
11
|
+
const compression = require("./compression.cjs");
|
|
12
|
+
const cors = require("./cors.cjs");
|
|
13
|
+
const requestBody = require("./requestBody.cjs");
|
|
14
14
|
const node_stream = require("node:stream");
|
|
15
15
|
const node_url = require("node:url");
|
|
16
16
|
const node_process = require("node:process");
|
|
@@ -110,13 +110,12 @@ class Application {
|
|
|
110
110
|
for (const middleware of this.middlewares) {
|
|
111
111
|
koa.use(middleware);
|
|
112
112
|
}
|
|
113
|
-
koa.use(
|
|
114
|
-
|
|
113
|
+
koa.use(compression.createCompressionMiddleware());
|
|
114
|
+
koa.use(requestBody.createRequestBodyMiddleware({
|
|
115
|
+
json: this.serverConfig.http?.requestBodySize ?? requestBody.defaultJsonBodyLimit,
|
|
116
|
+
form: requestBody.defaultFormBodyLimit
|
|
115
117
|
}));
|
|
116
|
-
koa.use(
|
|
117
|
-
jsonLimit: this.serverConfig.http?.requestBodySize || "1mb"
|
|
118
|
-
}));
|
|
119
|
-
koa.use(corsMiddleware({ exposeHeaders: ["X-Contember-Mutation"] }));
|
|
118
|
+
koa.use(cors.createCorsMiddleware({ exposeHeaders: ["X-Contember-Mutation"] }));
|
|
120
119
|
const versionMatch = this.version?.match(/^(0\.\d+|\d+)/);
|
|
121
120
|
const versionSimplified = versionMatch?.[1] ?? "unknown";
|
|
122
121
|
koa.use(async (ctx) => {
|