All files / apps/wp-editor/server/utils editor.ts

0% Statements 0/11
0% Branches 0/2
0% Functions 0/3
0% Lines 0/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29                                                         
import type { H3Event } from "h3";
import { Refusal, requireEnv } from "../../shared/refusal.ts";
import { createStore } from "../adapters/store.ts";
import { createWordPress } from "../adapters/wordpress.ts";
 
export const useStore = (event: H3Event) =>
    createStore(requireEnv("NUXT_EDITOR_STORE", useRuntimeConfig(event).editor.store));
 
export const useWordPress = (event: H3Event) => {
    const { baseURL, username, applicationPassword } = useRuntimeConfig(event).wordpress;
 
    return createWordPress({
        baseURL: requireEnv("NUXT_WORDPRESS_BASE_URL", baseURL),
        username: requireEnv("NUXT_WORDPRESS_USERNAME", username),
        applicationPassword: requireEnv("NUXT_WORDPRESS_APPLICATION_PASSWORD", applicationPassword),
    });
};
 
/** A broken rule comes back as a 409 whose message the UI shows as-is. */
export const refusing = async <T>(run: () => Promise<T>): Promise<T> => {
    try {
        return await run();
    } catch (error) {
        if (error instanceof Refusal)
            throw createError({ statusCode: 409, message: error.message });
        throw error;
    }
};