@topgroup/diginext
Version:
A BUILD SERVER & CLI to deploy apps to any Kubernetes clusters.
197 lines (196 loc) • 9.09 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const dist_1 = require("tsoa/dist");
const interfaces = __importStar(require("../interfaces"));
const dxDomain = __importStar(require("../modules/diginext/dx-domain"));
const BaseController_1 = __importDefault(require("./BaseController"));
let DomainController = class DomainController extends BaseController_1.default {
/**
* Create new Diginext domain
*/
async createDiginextDomain(body, queryParams) {
// validate
if (!body.name)
return interfaces.respondFailure({ msg: `Subdomain name is required.` });
if (!body.data)
return interfaces.respondFailure({ msg: `Value of A RECORD is required (usually the IP address).` });
const dxKey = this.workspace.dx_key;
if (!body.userId)
body.userId = this.user.dxUserId;
// process
const res = await dxDomain.dxCreateDomain(body, dxKey);
return res;
}
/**
* Get all Diginext domains
*/
async getDiginextDomains() {
const dxKey = this.workspace.dx_key;
const res = await dxDomain.dxGetDomains(dxKey);
return res;
}
/**
* Get all Diginext domain records
*/
async getDiginextDomainRecords(queryParams) {
const dxKey = this.workspace.dx_key;
console.log("OPTIONS :>>", this.options);
console.log("DEBUGGING :>>", this.options.isDebugging);
console.log("DXKEY :>>", dxKey);
const res = await dxDomain.dxGetAllDomainRecords(dxKey, { isDebugging: this.options.isDebugging });
return res;
}
/**
* Get a Diginext domain record by name
*/
async getDiginextDomainRecordByName(recordName, queryParams) {
var _a, _b, _c, _d;
// Detailed debugging
console.log("DomainController > Debug > Raw Inputs :>>", {
pathParams: this.req.params,
routeParams: (_b = (_a = this.req) === null || _a === void 0 ? void 0 : _a.route) === null || _b === void 0 ? void 0 : _b.params,
recordName,
queryParams,
});
// Explicit extraction and validation
const extractedRecordName = ((_c = this.req.params) === null || _c === void 0 ? void 0 : _c.recordName) || (typeof recordName === "string" ? recordName : undefined);
if (!extractedRecordName) {
throw new Error(`Invalid or missing recordName. Received: ${JSON.stringify(recordName)}`);
}
const dxKey = this.workspace.dx_key;
const type = (queryParams === null || queryParams === void 0 ? void 0 : queryParams.type) || ((_d = this.filter) === null || _d === void 0 ? void 0 : _d.type) || "A";
const res = await dxDomain.dxGetDomainRecordByName({ name: extractedRecordName, type }, dxKey);
return res;
}
/**
* Update a Diginext domain record
*/
async updateDiginextDomainRecord(recordName, body, queryParams) {
var _a, _b;
// Explicit extraction and validation
const extractedRecordName = ((_a = this.req.params) === null || _a === void 0 ? void 0 : _a.recordName) || (typeof recordName === "string" ? recordName : undefined);
if (!extractedRecordName) {
throw new Error(`Invalid or missing recordName. Received: ${JSON.stringify(recordName)}`);
}
console.log("BODY :>>", this.req.body);
const dxKey = this.workspace.dx_key;
const type = (queryParams === null || queryParams === void 0 ? void 0 : queryParams.type) || ((_b = this.filter) === null || _b === void 0 ? void 0 : _b.type) || "A";
const res = await dxDomain.dxUpdateDomainRecord({ name: extractedRecordName, type }, this.req.body, dxKey);
return res;
}
/**
* Delete a Diginext domain record
*/
async deleteDiginextDomainRecord(recordName, queryParams) {
var _a;
// Explicit extraction and validation
const extractedRecordName = ((_a = this.req.params) === null || _a === void 0 ? void 0 : _a.recordName) || (typeof recordName === "string" ? recordName : undefined);
if (!extractedRecordName) {
throw new Error(`Invalid or missing recordName. Received: ${JSON.stringify(recordName)}`);
}
const dxKey = this.workspace.dx_key;
const res = await dxDomain.dxDeleteDomainRecord({ name: extractedRecordName, type: (queryParams === null || queryParams === void 0 ? void 0 : queryParams.type) || "A" }, dxKey);
return res;
}
};
__decorate([
(0, dist_1.Security)("api_key"),
(0, dist_1.Security)("jwt"),
(0, dist_1.Post)("/"),
__param(0, (0, dist_1.Body)()),
__param(1, (0, dist_1.Queries)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, Object]),
__metadata("design:returntype", Promise)
], DomainController.prototype, "createDiginextDomain", null);
__decorate([
(0, dist_1.Security)("api_key"),
(0, dist_1.Security)("jwt"),
(0, dist_1.Get)("/"),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], DomainController.prototype, "getDiginextDomains", null);
__decorate([
(0, dist_1.Security)("api_key"),
(0, dist_1.Security)("jwt"),
(0, dist_1.Get)("/records"),
__param(0, (0, dist_1.Queries)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], DomainController.prototype, "getDiginextDomainRecords", null);
__decorate([
(0, dist_1.Security)("api_key"),
(0, dist_1.Security)("jwt"),
(0, dist_1.Get)("/records/:recordName"),
__param(0, (0, dist_1.Path)()),
__param(1, (0, dist_1.Queries)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Object]),
__metadata("design:returntype", Promise)
], DomainController.prototype, "getDiginextDomainRecordByName", null);
__decorate([
(0, dist_1.Security)("api_key"),
(0, dist_1.Security)("jwt"),
(0, dist_1.Patch)("/records/:recordName"),
__param(0, (0, dist_1.Path)()),
__param(1, (0, dist_1.Body)()),
__param(2, (0, dist_1.Queries)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Object, Object]),
__metadata("design:returntype", Promise)
], DomainController.prototype, "updateDiginextDomainRecord", null);
__decorate([
(0, dist_1.Security)("api_key"),
(0, dist_1.Security)("jwt"),
(0, dist_1.Delete)("/records/:recordName"),
__param(0, (0, dist_1.Path)()),
__param(1, (0, dist_1.Queries)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Object]),
__metadata("design:returntype", Promise)
], DomainController.prototype, "deleteDiginextDomainRecord", null);
DomainController = __decorate([
(0, dist_1.Tags)("Domain"),
(0, dist_1.Route)("domain")
], DomainController);
exports.default = DomainController;