UNPKG

@lucidcms/core

Version:

The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.

1 lines 2.31 kB
{"version":3,"file":"lifecycle.mjs","names":[],"sources":["../../../src/libs/email/lifecycle.ts"],"sourcesContent":["import type { Config } from \"../../types/config.js\";\nimport { createAdapterLifecycleContext } from \"../runtime/adapter-lifecycle.js\";\nimport type {\n\tAdapterLifecyclePurpose,\n\tAdapterRuntimeContext,\n\tEnvironmentVariables,\n} from \"../runtime/types.js\";\nimport getEmailAdapter from \"./get-adapter.js\";\nimport type { EmailAdapterInstance } from \"./types.js\";\n\n/** Resolve the configured email adapter and run its init lifecycle hook. */\nexport const getInitializedEmailAdapter = async (\n\tconfig: Config,\n\toptions: {\n\t\tenv?: EnvironmentVariables;\n\t\truntimeContext?: AdapterRuntimeContext;\n\t\tpurpose?: AdapterLifecyclePurpose;\n\t} = {},\n): Promise<EmailAdapterInstance> => {\n\tconst adapter = await getEmailAdapter(config);\n\tconst context = createAdapterLifecycleContext({\n\t\tconfig,\n\t\tenv: options.env,\n\t\truntimeContext: options.runtimeContext,\n\t\tpurpose: options.purpose,\n\t});\n\n\ttry {\n\t\tawait adapter.lifecycle?.init?.(context);\n\t} catch (error) {\n\t\tawait Promise.allSettled([adapter.lifecycle?.destroy?.(context)]);\n\t\tthrow error;\n\t}\n\n\treturn adapter;\n};\n\n/** Run an email adapter destroy lifecycle hook when one exists. */\nexport const destroyEmailAdapter = async (\n\tadapter: EmailAdapterInstance | undefined,\n\toptions: {\n\t\tconfig: Config;\n\t\tenv?: EnvironmentVariables;\n\t\truntimeContext?: AdapterRuntimeContext;\n\t\tpurpose?: AdapterLifecyclePurpose;\n\t},\n): Promise<void> => {\n\tif (!adapter) return;\n\n\tawait adapter.lifecycle?.destroy?.(\n\t\tcreateAdapterLifecycleContext({\n\t\t\tconfig: options.config,\n\t\t\tenv: options.env,\n\t\t\truntimeContext: options.runtimeContext,\n\t\t\tpurpose: options.purpose,\n\t\t}),\n\t);\n};\n"],"mappings":"kHAWA,MAAa,EAA6B,MACzC,EACA,EAII,CAAC,IAC8B,CACnC,IAAM,EAAU,MAAM,EAAgB,CAAM,EACtC,EAAU,EAA8B,CAC7C,SACA,IAAK,EAAQ,IACb,eAAgB,EAAQ,eACxB,QAAS,EAAQ,OAClB,CAAC,EAED,GAAI,CACH,MAAM,EAAQ,WAAW,OAAO,CAAO,CACxC,OAAS,EAAO,CAEf,MADA,MAAM,QAAQ,WAAW,CAAC,EAAQ,WAAW,UAAU,CAAO,CAAC,CAAC,EAC1D,CACP,CAEA,OAAO,CACR,EAGa,EAAsB,MAClC,EACA,IAMmB,CACd,GAEL,MAAM,EAAQ,WAAW,UACxB,EAA8B,CAC7B,OAAQ,EAAQ,OAChB,IAAK,EAAQ,IACb,eAAgB,EAAQ,eACxB,QAAS,EAAQ,OAClB,CAAC,CACF,CACD"}