UNPKG

@coursebuilder/core

Version:

Core package for Course Builder

1 lines 5.3 kB
{"version":3,"sources":["../../../src/lib/utils/assert.ts","../../../src/errors.ts"],"sourcesContent":["import { CourseBuilderAdapter } from '../../adapters'\nimport {\n\tMissingAdapter,\n\tMissingAdapterMethods,\n\tUnsupportedStrategy,\n} from '../../errors'\nimport { CourseBuilderConfig } from '../../index'\nimport { RequestInternal } from '../../types'\nimport { WarningCode } from './logger'\n\ntype ConfigError = MissingAdapter | MissingAdapterMethods | UnsupportedStrategy\n\nlet hasTranscript = false\nlet warned = false\n\nexport function assertConfig(\n\trequest: RequestInternal,\n\toptions: CourseBuilderConfig,\n): ConfigError | WarningCode[] {\n\tconst { url } = request\n\tconst warnings: WarningCode[] = []\n\n\tif (!warned && options.debug) warnings.push('debug-enabled')\n\n\t// Keep track of webauthn providers that use conditional UI\n\n\tfor (const p of options.providers) {\n\t\tconst provider = typeof p === 'function' ? p() : p\n\t\tif (provider.type === 'transcription') {\n\t\t\thasTranscript = true\n\t\t}\n\t}\n\n\tconst { adapter } = options\n\n\tlet requiredMethods: (keyof CourseBuilderAdapter)[] = []\n\n\tif (hasTranscript) {\n\t}\n\n\tif (adapter) {\n\t\tconst missing = requiredMethods.filter((m) => !(m in adapter))\n\n\t\tif (missing.length) {\n\t\t\treturn new MissingAdapterMethods(\n\t\t\t\t`Required adapter methods were missing: ${missing.join(', ')}`,\n\t\t\t)\n\t\t}\n\t}\n\n\tif (!warned) warned = true\n\n\treturn warnings\n}\n","type ErrorOptions = Error | Record<string, unknown>\n\ntype ErrorType =\n\t| 'AdapterError'\n\t| 'UnknownAction'\n\t| 'UnsupportedStrategy'\n\t| 'MissingAdapter'\n\t| 'MissingAdapterMethods'\n\nexport class CourseBuilderError extends Error {\n\t/** The error type. Used to identify the error in the logs. */\n\ttype: ErrorType\n\t/**\n\t * Determines on which page an error should be handled. Typically `signIn` errors can be handled in-page.\n\t * Default is `\"error\"`.\n\t * @internal\n\t */\n\tkind?: 'error'\n\tcause?: Record<string, unknown> & { err?: Error }\n\tconstructor(\n\t\tmessage?: string | Error | ErrorOptions,\n\t\terrorOptions?: ErrorOptions,\n\t) {\n\t\tif (message instanceof Error) {\n\t\t\tsuper(undefined, {\n\t\t\t\tcause: { err: message, ...(message.cause as any), ...errorOptions },\n\t\t\t})\n\t\t} else if (typeof message === 'string') {\n\t\t\tif (errorOptions instanceof Error) {\n\t\t\t\terrorOptions = { err: errorOptions, ...(errorOptions.cause as any) }\n\t\t\t}\n\t\t\tsuper(message, errorOptions)\n\t\t} else {\n\t\t\tsuper(undefined, message)\n\t\t}\n\t\tthis.name = this.constructor.name\n\t\t// @ts-expect-error https://github.com/microsoft/TypeScript/issues/3841\n\t\tthis.type = this.constructor.type ?? 'CourseBuilderError'\n\t\t// @ts-expect-error https://github.com/microsoft/TypeScript/issues/3841\n\t\tthis.kind = this.constructor.kind ?? 'error'\n\n\t\tError.captureStackTrace?.(this, this.constructor)\n\t\tconst url = `https://errors.authjs.dev#${this.type.toLowerCase()}`\n\t\tthis.message += `${this.message ? '. ' : ''}Read more at ${url}`\n\t}\n}\n\nexport class AdapterError extends CourseBuilderError {\n\tstatic type = 'AdapterError'\n}\n\nexport class UnsupportedStrategy extends CourseBuilderError {\n\tstatic type = 'UnsupportedStrategy'\n}\n\nexport class MissingAdapter extends CourseBuilderError {\n\tstatic type = 'MissingAdapter'\n}\n\nexport class MissingAdapterMethods extends CourseBuilderError {\n\tstatic type = 'MissingAdapterMethods'\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA;;;;;;;ACQO,IAAMA,sBAAN,MAAMA,4BAA2BC,MAAAA;EAUvCC,YACCC,SACAC,cACC;;;AAXFC;;AAMAC;;;;;;AACAC;AAIE;;AACD,QAAIJ,mBAAmBF,OAAO;AAC7B,cAAMO,QAAW;QAChBD,OAAO;UAAEE,KAAKN;UAAS,GAAIA,QAAQI;UAAe,GAAGH;QAAa;MACnE,CAAA;IACD,WAAW,OAAOD,YAAY,UAA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MAAI,CAACnB;AAAQA,aAAS;AAEtB,SAAOK;AACR;AAtCgBJ;","names":["CourseBuilderError","Error","constructor","message","errorOptions","type","kind","cause","undefined","err","name","captureStackTrace","url","toLowerCase","MissingAdapterMethods","CourseBuilderError","type","hasTranscript","warned","assertConfig","request","options","url","warnings","debug","push","p","providers","provider","type","adapter","requiredMethods","missing","filter","m","length","MissingAdapterMethods","join"]}