diff --git a/packages/config/src/ConfigService.spec.ts b/packages/config/src/ConfigService.spec.ts index f5069556b..85f3d3c18 100644 --- a/packages/config/src/ConfigService.spec.ts +++ b/packages/config/src/ConfigService.spec.ts @@ -24,7 +24,7 @@ describe('Log Configuration', () => { it('Tests the default Log Level', () => { if (process.env.DEBUG === 'true') { expect(testLogger.getLogLevel()).toEqual(LogLevel.Debug) - } else expect(testLogger.getLogLevel()).toEqual(LogLevel.Error) + } else expect(testLogger.getLogLevel()).toEqual(LogLevel.Warn) }) it('modifies the Log Level of all Loggers to the desired Level', () => { @@ -44,7 +44,7 @@ describe('Log Configuration', () => { describe('Configuration Service', () => { it('has configuration Object with default values', () => { - expect(ConfigService.get('logLevel')).toEqual(LogLevel.Error) + expect(ConfigService.get('logLevel')).toEqual(LogLevel.Warn) expect(() => ConfigService.get('api')).toThrowErrorMatchingInlineSnapshot( `"The blockchain API is not set. Did you forget to call \`Kilt.connect(…)\` or \`Kilt.init(…)\`?"` ) diff --git a/packages/config/src/ConfigService.ts b/packages/config/src/ConfigService.ts index d9e68b4a8..38d22fc3c 100644 --- a/packages/config/src/ConfigService.ts +++ b/packages/config/src/ConfigService.ts @@ -24,12 +24,17 @@ import { } from 'typescript-logging' import type { SubscriptionPromise } from '@kiltprotocol/types' -const DEFAULT_DEBUG_LEVEL = - typeof process !== 'undefined' && - process.env?.DEBUG && - process.env.DEBUG === 'true' - ? LogLevel.Debug - : LogLevel.Error +const DEFAULT_DEBUG_LEVEL = (() => { + if (typeof process !== 'undefined') { + if (process.env.DEBUG === 'true') { + return LogLevel.Debug + } + if (process.env.NODE_ENV && process.env.NODE_ENV !== 'production') { + return LogLevel.Warn + } + } + return LogLevel.Error +})() export type configOpts = { api: ApiPromise diff --git a/packages/core/src/ctype/CType.ts b/packages/core/src/ctype/CType.ts index 6c061809d..70c545dc0 100644 --- a/packages/core/src/ctype/CType.ts +++ b/packages/core/src/ctype/CType.ts @@ -30,6 +30,27 @@ import { CTypeModelV1, } from './CType.schemas.js' +let notifyDeprecated: (cTypeId: ICType['$id']) => void = () => { + // do nothing +} +if ( + typeof process !== 'undefined' && + process.env?.NODE_ENV && + process.env.NODE_ENV !== 'production' +) { + const logger = ConfigService.LoggingFactory.getLogger('deprecated') + const alreadyNotified = new Set() + notifyDeprecated = (cTypeId) => { + if (alreadyNotified.has(cTypeId)) { + return + } + logger.warn( + `Your application has processed the CType '${cTypeId}' which follows the meta schema '${CTypeModelDraft01.$id}'. This class of schemas has known issues that can result in unexpected properties being present in a credential. Consider switching to a CType based on meta schema ${CTypeModelV1.$id} which fixes this issue.` + ) + alreadyNotified.add(cTypeId) + } +} + /** * Utility for (re)creating CType hashes. Sorts the schema and strips the $id property (which contains the CType hash) before stringifying. * @@ -136,6 +157,9 @@ export function verifyClaimAgainstSchema( messages?: string[] ): void { verifyObjectAgainstSchema(schema, CTypeModel, messages) + if (schema.$schema === CTypeModelDraft01.$id) { + notifyDeprecated(schema.$id) + } verifyObjectAgainstSchema(claimContents, schema, messages) } @@ -162,6 +186,9 @@ export async function verifyStored(ctype: ICType): Promise { */ export function verifyDataStructure(input: ICType): void { verifyObjectAgainstSchema(input, CTypeModel) + if (input.$schema === CTypeModelDraft01.$id) { + notifyDeprecated(input.$id) + } const idFromSchema = getIdForSchema(input) if (idFromSchema !== input.$id) { throw new SDKErrors.CTypeIdMismatchError(idFromSchema, input.$id)