import { __awaiter } from "tslib";
import { DefaultApi, Configuration } from "@qorebase/sdk";
import { qoreConfig } from "../../../app/hooks/qoreStorageClient";
export default function handler(req, res) {
    var _a, _b, _c, _d, _e, _f, _g, _h;
    return __awaiter(this, void 0, void 0, function* () {
        const consoleSdk = new DefaultApi(new Configuration({
            apiKey: qoreConfig.adminSecret,
            basePath: qoreConfig.endpoint,
        }));
        const { data: releases } = yield consoleSdk.execute({
            operations: [
                {
                    // @ts-ignore
                    operation: "Select",
                    instruction: {
                        table: "release_log",
                        condition: {
                            release: {
                                project: req.query.projectID,
                            },
                            stage: "staging",
                        },
                        orderBy: {
                            updated_at: "DESC",
                        },
                        limit: 1,
                    },
                },
            ],
        });
        const endpoint = 
        // @ts-ignore
        "https://" +
            ((_d = (_c = (_b = (_a = releases.results) === null || _a === void 0 ? void 0 : _a.undefined) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.user_overrides) === null || _d === void 0 ? void 0 : _d["qore-data"].domains.split(",")[0]);
        const adminSecret = 
        // @ts-ignore
        (_h = (_g = (_f = (_e = releases.results) === null || _e === void 0 ? void 0 : _e.undefined) === null || _f === void 0 ? void 0 : _f[0]) === null || _g === void 0 ? void 0 : _g.user_overrides) === null || _h === void 0 ? void 0 : _h["qore-data"].admin_secret;
        const sdk = new DefaultApi(new Configuration({
            apiKey: adminSecret,
            basePath: endpoint,
        }));
        yield sdk.createRow("users", { data: req.body });
        res.status(200).json({ status: "ok" });
    });
}
//# sourceMappingURL=register.js.map