import { __awaiter } from "tslib";
import { QoreClient } from "@qorebase/client";
import { qoreConfig } from "../../../../../app/hooks/qoreStorageClient";
const pageID = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
    const client = new QoreClient(qoreConfig);
    client.project.axios.defaults.headers["x-qore-engine-admin-secret"] =
        qoreConfig.adminSecret;
    const { data: revision } = yield client
        .table("revisions")
        .readRow(req.query.revisionID)
        .toPromise();
    if (!revision) {
        return res.status(404).json({
            data: {},
            error: {
                type: "NO_REVISION",
                message: "Application schema not found!",
            },
        });
    }
    const page = revision.data.maps.page[req.query.pageID];
    if (!page) {
        return res.status(404).json({
            data: {},
            error: {
                type: "PAGE_NOT_FOUND",
                message: "Page schema not found!",
            },
        });
    }
    const components = page.components.flatMap(({ component }) => revision.data.maps.component[component]
        ? [revision.data.maps.component[component]]
        : []);
    res.status(200).json({
        data: {
            components,
            page,
        },
    });
});
export default pageID;
//# sourceMappingURL=%5BpageID%5D.js.map