edmaxlabs-tools 1.0.1 ā 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.deployAuthenticationRules = deployAuthenticationRules;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const config_1 = require("../config");
|
|
10
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
11
|
+
const FormData = require("form-data");
|
|
12
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
13
|
+
const constants_1 = require("../constants");
|
|
14
|
+
// Example: deploy function
|
|
15
|
+
async function deployAuthenticationRules() {
|
|
16
|
+
const cwd = process.cwd();
|
|
17
|
+
const existingConfig = await (0, config_1.loadConfig)(cwd);
|
|
18
|
+
if (!existingConfig) {
|
|
19
|
+
console.log(chalk_1.default.red("ā No project initialized. Run `edmaxlabs init` first."));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const rules = `${path_1.default.join(cwd, existingConfig.auth.rules)}`;
|
|
23
|
+
if (!fs_extra_1.default.existsSync(rules)) {
|
|
24
|
+
console.log(chalk_1.default.red("Authentication Rules Not Found at - "), chalk_1.default.underline(rules));
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const form = new FormData();
|
|
28
|
+
form.append("file", fs_extra_1.default.createReadStream(rules), path_1.default.basename(rules));
|
|
29
|
+
form.append("hostname", existingConfig.hosting.host);
|
|
30
|
+
form.append("project", existingConfig.project.id);
|
|
31
|
+
const response = await (0, node_fetch_1.default)(`https://api.edmaxlabs.com/api/v2/auth/rules/compile`, {
|
|
32
|
+
method: "POST",
|
|
33
|
+
headers: {
|
|
34
|
+
authorization: constants_1.CLIENT_BEARER_TOKEN,
|
|
35
|
+
...form.getHeaders(), // š REQUIRED in Node
|
|
36
|
+
},
|
|
37
|
+
body: form,
|
|
38
|
+
});
|
|
39
|
+
const rr = await response.json();
|
|
40
|
+
const data = rr;
|
|
41
|
+
if (!response.ok) {
|
|
42
|
+
console.log(chalk_1.default.red(`Authentication Rules Deployment Failed : ${data.error}`));
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
if (data.success) {
|
|
46
|
+
console.log(chalk_1.default.green(`Authentication Rules Deployed Successful\n`));
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
console.log(chalk_1.default.red(`Authentication Rules Deployment Failed - ${data.error}`));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -18,6 +18,8 @@ const constants_1 = require("../constants");
|
|
|
18
18
|
const zipFile_1 = require("../utils/zipFile");
|
|
19
19
|
const functions_1 = require("./functions");
|
|
20
20
|
const database_1 = require("./database");
|
|
21
|
+
const storage_1 = require("./storage");
|
|
22
|
+
const authentication_1 = require("./authentication");
|
|
21
23
|
// Example: deploy function
|
|
22
24
|
async function deployCommand() {
|
|
23
25
|
console.log(chalk_1.default.cyan.bold("\nEdmaxLabs - Deploy\n"));
|
|
@@ -68,11 +70,11 @@ async function deployCommand() {
|
|
|
68
70
|
break;
|
|
69
71
|
case "storage":
|
|
70
72
|
console.log(chalk_1.default.green(`š¹ Storage Rules: ${config.storage.rules}`));
|
|
71
|
-
|
|
73
|
+
await (0, storage_1.deployStorageRules)();
|
|
72
74
|
break;
|
|
73
75
|
case "auth":
|
|
74
|
-
console.log(chalk_1.default.green(`š¹
|
|
75
|
-
|
|
76
|
+
console.log(chalk_1.default.green(`š¹ Auth Rules: ${config.authentication.rules}`));
|
|
77
|
+
await (0, authentication_1.deployAuthenticationRules)();
|
|
76
78
|
break;
|
|
77
79
|
default:
|
|
78
80
|
console.log(chalk_1.default.yellow(`ā Unknown service: ${service}`));
|
|
@@ -87,6 +87,7 @@ async function initCommand() {
|
|
|
87
87
|
functions: {},
|
|
88
88
|
database: {},
|
|
89
89
|
storage: {},
|
|
90
|
+
auth: {},
|
|
90
91
|
};
|
|
91
92
|
if (services.includes("hosting")) {
|
|
92
93
|
const { hosting = "public" } = await inquirer_1.default.prompt([
|
|
@@ -165,6 +166,23 @@ async function initCommand() {
|
|
|
165
166
|
},
|
|
166
167
|
};
|
|
167
168
|
}
|
|
169
|
+
if (services.includes("auth")) {
|
|
170
|
+
const { rule = "eauth.rules.json" } = await inquirer_1.default.prompt([
|
|
171
|
+
{
|
|
172
|
+
type: "input",
|
|
173
|
+
name: "rule",
|
|
174
|
+
message: "Authentication : Rules : ",
|
|
175
|
+
default: "eauth.rules.json",
|
|
176
|
+
},
|
|
177
|
+
]);
|
|
178
|
+
fs_extra_1.default.writeFileSync(path_1.default.join(cwd, rule), JSON.stringify({}));
|
|
179
|
+
payload = {
|
|
180
|
+
...payload,
|
|
181
|
+
auth: {
|
|
182
|
+
rules: rule,
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
}
|
|
168
186
|
await (0, config_1.saveConfig)(cwd, payload);
|
|
169
187
|
console.log(chalk_1.default.green(`\nā
Project initialized at ${path_1.default.join(cwd, ".edmaxlabs")}`));
|
|
170
188
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.deployStorageRules = deployStorageRules;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const config_1 = require("../config");
|
|
10
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
11
|
+
const FormData = require("form-data");
|
|
12
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
13
|
+
const constants_1 = require("../constants");
|
|
14
|
+
// Example: deploy function
|
|
15
|
+
async function deployStorageRules() {
|
|
16
|
+
const cwd = process.cwd();
|
|
17
|
+
const existingConfig = await (0, config_1.loadConfig)(cwd);
|
|
18
|
+
if (!existingConfig) {
|
|
19
|
+
console.log(chalk_1.default.red("ā No project initialized. Run `edmaxlabs init` first."));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const rules = `${path_1.default.join(cwd, existingConfig.storage.rules)}`;
|
|
23
|
+
if (!fs_extra_1.default.existsSync(rules)) {
|
|
24
|
+
console.log(chalk_1.default.red("Storage Rules Not Found at - "), chalk_1.default.underline(rules));
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const form = new FormData();
|
|
28
|
+
form.append("file", fs_extra_1.default.createReadStream(rules), path_1.default.basename(rules));
|
|
29
|
+
form.append("hostname", existingConfig.hosting.host);
|
|
30
|
+
form.append("project", existingConfig.project.id);
|
|
31
|
+
const response = await (0, node_fetch_1.default)(`https://api.edmaxlabs.com/api/v2/storage/rules/compile`, {
|
|
32
|
+
method: "POST",
|
|
33
|
+
headers: {
|
|
34
|
+
authorization: constants_1.CLIENT_BEARER_TOKEN,
|
|
35
|
+
...form.getHeaders(), // š REQUIRED in Node
|
|
36
|
+
},
|
|
37
|
+
body: form,
|
|
38
|
+
});
|
|
39
|
+
const rr = await response.json();
|
|
40
|
+
const data = rr;
|
|
41
|
+
if (!response.ok) {
|
|
42
|
+
console.log(chalk_1.default.red(`Storage Rules Deployment Failed : ${data.error}`));
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
if (data.success) {
|
|
46
|
+
console.log(chalk_1.default.green(`Storage Rules Deployed Successful\n`));
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
console.log(chalk_1.default.red(`Storage Rules Deployment Failed - ${data.error}`));
|
|
50
|
+
}
|
|
51
|
+
}
|