import * as z from "zod"; import {requestRetryOptionsSchema} from "../common.ts"; import {commonClientConfigSchema, commonClientDataSchema, type EnvClientSchema} from "./index.ts"; import {lastfmClientOptionsSchema} from "./lastfm.ts"; import { httpUrl } from "../../../../utils/ZodUtils.ts"; export const librefmDataSchema = z.object({ ...commonClientDataSchema.shape, ...requestRetryOptionsSchema.shape, /** * Optional Secret for Libre.fm account * * This can be anything, or it will be generated by multi-scrobbler * * @examples ["anyValue"] * */ apiKey: z.string().optional().meta({ description: "Optional Secret for Libre.fm account", examples: ["anyValue"] }), /** * Optional Secret for Libre.fm account * * This can be anything, or it will be generated by multi-scrobbler * * @examples ["anyValue"] * */ secret: z.string().optional().meta({ description: "Optional Secret for Libre.fm account", examples: ["anyValue"] }), /** * Optional session id returned from a completed auth flow * */ session: z.string().optional().meta({ description: "Optional session id returned from a completed auth flow" }), path: z.string().optional(), /** * (Optional) The host and path prefix for your Libre.fm instance * * @default 'https://libre.fm/2.0/' */ urlBase: httpUrl.optional().meta({ description: "(Optional) The host and path prefix for your Libre.fm instance", default: "https://libre.fm/2.0/" }), /** * Optional URI to use for callback. Specify this if callback should be different than the default. MUST have "librefm/callback" in the URL somewhere. * * @default "http://localhost:9078/librefm/callback" * @examples ["http://localhost:9078/librefm/callback"] * */ redirectUri: z.string().optional().meta({ description: "Optional URI to use for callback.", default: "http://localhost:9078/librefm/callback", examples: ["http://localhost:9078/librefm/callback"] }), }); export type LibrefmData = z.infer; const envDataSchema = z.object({ LIBREFM_API_KEY: librefmDataSchema.shape.apiKey, LIBREFM_SECRET: librefmDataSchema.shape.secret, LIBREFM_REDIRECT_URI: librefmDataSchema.shape.redirectUri, LIBREFM_SESSION: librefmDataSchema.shape.session, LIBREFM_URLBASE: librefmDataSchema.shape.urlBase, }); export const envSchemas: EnvClientSchema = { env: envDataSchema, prefix: 'LIBREFM', toConfig: (partial) => ({ configureAs: 'client', data: { apiKey: partial.LIBREFM_API_KEY, secret: partial.LIBREFM_SECRET, redirectUri: partial.LIBREFM_REDIRECT_URI, session: partial.LIBREFM_SESSION, urlBase: partial.LIBREFM_URLBASE } }) }; export const librefmClientOptionsSchema = z.object({ ...lastfmClientOptionsSchema.shape, }); export type LibrefmClientOptions = z.infer; export const librefmClientConfigSchema = z.object({ ...commonClientConfigSchema.shape, /** * Should always be `client` when using Librefm as a client * * @default client * @examples ["client"] * */ configureAs: z.union([z.literal('client'), z.literal('source')]).optional().meta({ description: "Should always be `client` when using Librefm as a client", default: "client", examples: ["client"] }), data: librefmDataSchema, options: librefmClientOptionsSchema.optional(), }); export type LibrefmClientConfig = z.infer; export const librefmClientAIOConfigSchema = z.object({ ...librefmClientConfigSchema.shape, type: z.literal('librefm'), }).meta({title: 'Libre.fm'}); export type LibrefmClientAIOConfig = z.infer;