studiocms
Version:
Astro Native CMS for AstroDB. Built from the ground up by the Astro community.
52 lines (51 loc) • 2 kB
JavaScript
import { NotificationSettingsDefaults } from "../../../consts.js";
import { Effect, genLogger } from "../../../effect.js";
import { AstroDB } from "../effect/index.js";
import { SDKCoreError, StudioCMS_SDK_Error } from "../errors.js";
import { SDKCore_CONFIG } from "./config.js";
class SDKCore_NotificationSettings extends Effect.Service()(
"studiocms/sdk/SDKCore/modules/notificationSettings",
{
dependencies: [AstroDB.Default, SDKCore_CONFIG.Default],
effect: genLogger("studiocms/sdk/SDKCore/modules/notificationSettings/effect")(function* () {
const { notificationConfig } = yield* SDKCore_CONFIG;
const notificationSettings = {
site: {
/**
* Retrieves the site-wide notification settings.
* @returns An Effect that resolves to the current notification settings.
* @throws SDKCoreError when a database error occurs.
*/
get: () => Effect.gen(function* () {
const data = yield* notificationConfig.get();
if (!data) return yield* notificationConfig.init(NotificationSettingsDefaults);
return data;
}).pipe(
Effect.catchTags({
LibSQLClientError: (cause) => Effect.fail(
new SDKCoreError({
type: "LibSQLDatabaseError",
cause: new StudioCMS_SDK_Error(
`notificationSettings.site.get Error: ${cause}`
)
})
)
})
),
/**
* Updates the site-wide notification settings.
* @param settings - The new notification settings to be updated.
* @returns An Effect that resolves to the updated settings.
* @throws SDKCoreError when a database error occurs.
*/
update: (settings) => notificationConfig.update(settings)
}
};
return notificationSettings;
})
}
) {
}
export {
SDKCore_NotificationSettings
};