@joystick.js/node-canary 0.0.0-canary.33 → 0.0.0-canary.331
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.
- package/_package.json +2 -3
- package/dist/action/class.js +21 -0
- package/dist/api/get.js +15 -13
- package/dist/api/set.js +15 -13
- package/dist/app/accounts/createMetadataTableColumns.js +12 -0
- package/dist/app/accounts/deleteUser.js +7 -0
- package/dist/app/accounts/generateSession.js +2 -4
- package/dist/app/accounts/getBrowserSafeUser.js +5 -2
- package/dist/app/accounts/hasLoginTokenExpired.js +1 -2
- package/dist/app/accounts/index.js +2 -0
- package/dist/app/accounts/login.js +6 -0
- package/dist/app/accounts/recoverPassword.js +3 -0
- package/dist/app/accounts/resetPassword.js +6 -0
- package/dist/app/accounts/signup.js +50 -7
- package/dist/app/accounts/verifyEmail.js +3 -0
- package/dist/app/cluster.js +26 -0
- package/dist/app/databases/generate_sql_from_object.js +60 -0
- package/dist/app/databases/mongodb/buildConnectionString.js +1 -1
- package/dist/app/databases/mongodb/createAccountsIndexes.js +18 -0
- package/dist/app/databases/mongodb/createSessionsIndexes.js +10 -0
- package/dist/app/databases/mongodb/index.js +1 -1
- package/dist/app/databases/mongodb/queries/accounts.js +8 -1
- package/dist/app/databases/mongodb/queries/queues.js +51 -28
- package/dist/app/databases/mongodb/queries/sessions.js +26 -0
- package/dist/app/databases/postgresql/createSessionsIndexes.js +10 -0
- package/dist/app/databases/postgresql/createSessionsTables.js +14 -0
- package/dist/app/databases/postgresql/handleCleanupQueues.js +36 -0
- package/dist/app/databases/postgresql/index.js +88 -2
- package/dist/app/databases/postgresql/queries/accounts.js +5 -2
- package/dist/app/databases/postgresql/queries/queues.js +83 -38
- package/dist/app/databases/postgresql/queries/sessions.js +43 -0
- package/dist/app/databases/queryMap.js +6 -2
- package/dist/app/databases/stringToSnakeCase.js +6 -0
- package/dist/app/getBrowserSafeRequest.js +3 -2
- package/dist/app/index.js +229 -78
- package/dist/app/initExpress.js +1 -1
- package/dist/app/middleware/csp.js +2 -2
- package/dist/app/middleware/getTranslations.js +64 -0
- package/dist/app/middleware/get_insecure_landing_page_html.js +71 -0
- package/dist/app/middleware/hmr/client.js +13 -9
- package/dist/app/middleware/index.js +6 -5
- package/dist/app/middleware/insecure.js +3 -4
- package/dist/app/middleware/render.js +8 -66
- package/dist/app/middleware/session.js +12 -11
- package/dist/app/queues/index.js +82 -32
- package/dist/app/registerGetters.js +5 -6
- package/dist/app/registerSetters.js +5 -6
- package/dist/app/runGetter.js +17 -5
- package/dist/app/runSessionQuery.js +15 -0
- package/dist/app/runSetter.js +17 -5
- package/dist/app/sanitizeAPIResponse.js +1 -1
- package/dist/app/validateInstanceToken.js +16 -0
- package/dist/app/validateSession.js +8 -3
- package/dist/app/validateUploaderOptions.js +3 -3
- package/dist/app/validateUploads.js +12 -1
- package/dist/email/send.js +7 -1
- package/dist/email/templates/reset-password.js +0 -1
- package/dist/fixture/index.js +40 -0
- package/dist/index.js +19 -0
- package/dist/lib/escapeKeyValuePair.js +13 -0
- package/dist/lib/formatAPIError.js +0 -1
- package/dist/lib/getBuildPath.js +1 -1
- package/dist/lib/getSSLCertificates.js +3 -3
- package/dist/lib/importFile.js +7 -0
- package/dist/lib/isValidJSONString.js +1 -1
- package/dist/lib/log.js +0 -3
- package/dist/lib/objectToSQLKeysString.js +1 -1
- package/dist/lib/objectToSQLValuesString.js +1 -1
- package/dist/lib/serializeQueryParameters.js +1 -1
- package/dist/lib/timestamps.js +47 -0
- package/dist/lib/wait.js +8 -0
- package/dist/push/logs/index.js +35 -17
- package/dist/settings/load.js +3 -5
- package/dist/ssr/compileCSS.js +4 -4
- package/dist/ssr/findComponentInTree.js +1 -1
- package/dist/ssr/getAPIForDataFunctions.js +35 -0
- package/dist/ssr/getDataFromComponent.js +15 -0
- package/dist/ssr/index.js +19 -45
- package/dist/ssr/replaceWhenTags.js +2 -3
- package/dist/ssr/setHeadTagsInHTML.js +3 -3
- package/dist/test/index.js +9 -0
- package/dist/test/trackFunctionCall.js +17 -0
- package/dist/validation/inputWithSchema/index.js +3 -3
- package/dist/validation/schema/index.js +5 -5
- package/dist/websockets/index.js +4 -0
- package/getSanitizedContext.js +43 -0
- package/package.json +2 -2
- package/dist/app/accounts/roles/index.test.js +0 -123
- package/dist/app/index.test.js +0 -575
- package/dist/app/middleware/sanitizeRequestParameters.js +0 -26
- package/dist/email/send.test.js +0 -37
- package/dist/validation/index.test.js +0 -463
package/dist/app/runSetter.js
CHANGED
|
@@ -3,19 +3,31 @@ import formatAPIError from "../lib/formatAPIError.js";
|
|
|
3
3
|
import { isObject } from "../validation/lib/typeValidators.js";
|
|
4
4
|
import getOutput from "./getOutput.js";
|
|
5
5
|
import sanitizeAPIResponse from "./sanitizeAPIResponse.js";
|
|
6
|
-
|
|
6
|
+
import trackFunctionCall from "../test/trackFunctionCall.js";
|
|
7
|
+
import getSanitizedContext from "../../getSanitizedContext.js";
|
|
8
|
+
const handleRunSetter = async (name = "", setterOptions = {}, input = {}, output = {}, context = {}, APIOptions = {}) => {
|
|
7
9
|
try {
|
|
8
10
|
const shouldDisableSanitizationForSetter = setterOptions?.sanitize === false;
|
|
9
11
|
const shouldSanitizeOutput = (setterOptions?.sanitize || APIOptions?.sanitize) === true || isObject(APIOptions?.sanitize || setterOptions?.sanitize);
|
|
10
|
-
const
|
|
12
|
+
const sanitizedContext = getSanitizedContext(context);
|
|
13
|
+
trackFunctionCall(`node.api.setters.${name}`, [
|
|
14
|
+
input,
|
|
15
|
+
sanitizedContext
|
|
16
|
+
]);
|
|
17
|
+
const data = await setterOptions?.set(input, context);
|
|
11
18
|
const response = output ? getOutput(data, output) : data;
|
|
12
19
|
return !shouldDisableSanitizationForSetter && shouldSanitizeOutput ? sanitizeAPIResponse(response, setterOptions?.sanitize || APIOptions?.sanitize) : response;
|
|
13
20
|
} catch (exception) {
|
|
14
21
|
throw new Error(`[runSetter.handleRunSetter] ${exception.message}`);
|
|
15
22
|
}
|
|
16
23
|
};
|
|
17
|
-
const handleRunAuthorization = async (getterOptions = {}, input = {}, context = {}) => {
|
|
24
|
+
const handleRunAuthorization = async (name = "", getterOptions = {}, input = {}, context = {}) => {
|
|
18
25
|
try {
|
|
26
|
+
const sanitizedContext = getSanitizedContext(context);
|
|
27
|
+
trackFunctionCall(`node.api.setters.${name}.authorized`, [
|
|
28
|
+
input,
|
|
29
|
+
sanitizedContext
|
|
30
|
+
]);
|
|
19
31
|
const authorization = await getterOptions?.authorized(input, context);
|
|
20
32
|
if (typeof authorization === "boolean") {
|
|
21
33
|
return authorization;
|
|
@@ -77,7 +89,7 @@ const runSetter = async (options, { resolve, reject }) => {
|
|
|
77
89
|
}
|
|
78
90
|
}
|
|
79
91
|
if (typeof options?.setterOptions?.authorized === "function") {
|
|
80
|
-
const authorized = await handleRunAuthorization(options?.setterOptions, options?.input, options?.context);
|
|
92
|
+
const authorized = await handleRunAuthorization(options?.setterName, options?.setterOptions, options?.input, options?.context);
|
|
81
93
|
if (!authorized || typeof authorized === "string") {
|
|
82
94
|
return reject({
|
|
83
95
|
errors: [
|
|
@@ -87,7 +99,7 @@ const runSetter = async (options, { resolve, reject }) => {
|
|
|
87
99
|
}
|
|
88
100
|
}
|
|
89
101
|
if (typeof options?.setterOptions?.set === "function") {
|
|
90
|
-
const response = await handleRunSetter(options?.setterOptions, options?.input, options?.output, options?.context, options?.APIOptions);
|
|
102
|
+
const response = await handleRunSetter(options?.setterName, options?.setterOptions, options?.input, options?.output, options?.context, options?.APIOptions);
|
|
91
103
|
return resolve(response);
|
|
92
104
|
}
|
|
93
105
|
resolve();
|
|
@@ -9,7 +9,7 @@ const sanitizeAPIResponse = (data = null) => {
|
|
|
9
9
|
sanitizedData = escapeHTML(sanitizedData)?.trim();
|
|
10
10
|
}
|
|
11
11
|
if (util.isObject(sanitizedData) && !Array.isArray(sanitizedData)) {
|
|
12
|
-
sanitizedData = Object.entries(sanitizedData)?.reduce((result = {}, [key, value]) => {
|
|
12
|
+
sanitizedData = Object.entries(sanitizedData || {})?.reduce((result = {}, [key, value]) => {
|
|
13
13
|
result[key] = sanitizeAPIResponse(value);
|
|
14
14
|
return result;
|
|
15
15
|
}, {});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
const { readFile } = fs.promises;
|
|
3
|
+
var validateInstanceToken_default = (instance_token_from_headers = "") => {
|
|
4
|
+
return new Promise(async (resolve, reject) => {
|
|
5
|
+
const instance_token_from_disk = await readFile("/root/push/instance_token.txt", "utf-8");
|
|
6
|
+
const is_valid_token = instance_token_from_headers === instance_token_from_disk?.replace("\n", "");
|
|
7
|
+
if (is_valid_token) {
|
|
8
|
+
return resolve();
|
|
9
|
+
} else {
|
|
10
|
+
reject();
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
export {
|
|
15
|
+
validateInstanceToken_default as default
|
|
16
|
+
};
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import formatAPIError from "../lib/formatAPIError.js";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import runSessionQuery from "./runSessionQuery.js";
|
|
3
|
+
var validateSession_default = async (req = null, res = null) => {
|
|
4
4
|
const csrfToken = req?.headers["x-joystick-csrf"];
|
|
5
|
-
const session =
|
|
5
|
+
const session = await runSessionQuery("get_session", {
|
|
6
|
+
session_id: req?.cookies?.joystickSession
|
|
7
|
+
});
|
|
8
|
+
if (csrfToken === "joystick_test") {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
6
11
|
if (!session || session && session.csrf !== csrfToken) {
|
|
7
12
|
res.status(403).send(JSON.stringify({
|
|
8
13
|
errors: [formatAPIError(new Error("Unauthorized request."))]
|
|
@@ -20,7 +20,7 @@ const allowedS3Options = [
|
|
|
20
20
|
];
|
|
21
21
|
var validateUploaderOptions_default = (options = {}) => {
|
|
22
22
|
const errors = [];
|
|
23
|
-
const optionNames = Object.keys(options);
|
|
23
|
+
const optionNames = Object.keys(options || {});
|
|
24
24
|
optionNames.forEach((optionName) => {
|
|
25
25
|
if (!allowedOptions.includes(optionName)) {
|
|
26
26
|
errors.push(`${optionName} is not an allowed uploader option.`);
|
|
@@ -33,14 +33,14 @@ var validateUploaderOptions_default = (options = {}) => {
|
|
|
33
33
|
errors.push(`If an uploader provider is 's3', s3 object must be specified with configuration.`);
|
|
34
34
|
}
|
|
35
35
|
if (options?.provider?.includes("local") && options.local) {
|
|
36
|
-
Object.keys(options.local).forEach((optionName) => {
|
|
36
|
+
Object.keys(options.local || {}).forEach((optionName) => {
|
|
37
37
|
if (!allowedLocalOptions.includes(optionName)) {
|
|
38
38
|
errors.push(`local.${optionName} is not an allowed uploader option.`);
|
|
39
39
|
}
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
if (options?.provider?.includes("s3") && options.s3) {
|
|
43
|
-
Object.keys(options.s3).forEach((optionName) => {
|
|
43
|
+
Object.keys(options.s3 || {}).forEach((optionName) => {
|
|
44
44
|
if (!allowedS3Options.includes(optionName)) {
|
|
45
45
|
errors.push(`s3.${optionName} is not an allowed uploader option.`);
|
|
46
46
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import log from "../lib/log";
|
|
2
|
+
import trackFunctionCall from "../test/trackFunctionCall.js";
|
|
2
3
|
const handleCheckUpload = ({
|
|
3
4
|
uploaderName,
|
|
4
5
|
maxSizeInMegabytes,
|
|
@@ -49,6 +50,16 @@ const formatUploads = ({
|
|
|
49
50
|
try {
|
|
50
51
|
return Promise.all(uploads.map(async (upload) => {
|
|
51
52
|
const fileExtension = upload?.mimeType?.split("/").pop();
|
|
53
|
+
const fileNameIsFunction = typeof uploaderOptions?.fileName === "function";
|
|
54
|
+
if (fileNameIsFunction) {
|
|
55
|
+
trackFunctionCall(`node.uploaders.${uploaderName}.fileName`, [{
|
|
56
|
+
input,
|
|
57
|
+
fileName: upload?.originalname,
|
|
58
|
+
fileSize: upload?.size,
|
|
59
|
+
fileExtension,
|
|
60
|
+
mimeType: upload?.mimetype
|
|
61
|
+
}]);
|
|
62
|
+
}
|
|
52
63
|
return {
|
|
53
64
|
uploaderName,
|
|
54
65
|
providers: uploaderOptions?.providers,
|
|
@@ -56,7 +67,7 @@ const formatUploads = ({
|
|
|
56
67
|
s3: uploaderOptions?.s3,
|
|
57
68
|
maxSizeInMegabytes: typeof uploaderOptions?.maxSizeInMegabytes === "function" ? await uploaderOptions?.maxSizeInMegabytes({ input, upload }) : uploaderOptions?.maxSizeInMegabytes,
|
|
58
69
|
mimeTypes: uploaderOptions?.mimeTypes,
|
|
59
|
-
fileName:
|
|
70
|
+
fileName: fileNameIsFunction ? uploaderOptions.fileName({ input, fileName: upload?.originalname, fileSize: upload?.size, fileExtension, mimeType: upload?.mimetype }) : upload?.originalname,
|
|
60
71
|
originalFileName: upload?.originalname,
|
|
61
72
|
fileSize: upload?.size,
|
|
62
73
|
mimeType: upload?.mimetype,
|
package/dist/email/send.js
CHANGED
|
@@ -7,7 +7,13 @@ import settings from "../settings";
|
|
|
7
7
|
import validateSMTPSettings from "./validateSMTPSettings";
|
|
8
8
|
import render from "./render";
|
|
9
9
|
import getBuildPath from "../lib/getBuildPath";
|
|
10
|
-
|
|
10
|
+
import trackFunctionCall from "../test/trackFunctionCall.js";
|
|
11
|
+
var send_default = async (args) => {
|
|
12
|
+
const { template: templateName, props, base: baseName, ...restOfOptions } = args;
|
|
13
|
+
if (process.env.NODE_ENV === "test") {
|
|
14
|
+
trackFunctionCall("node.email.send", [args]);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
11
17
|
const validSMTPSettings = validateSMTPSettings(settings?.config?.email?.smtp);
|
|
12
18
|
if (!validSMTPSettings) {
|
|
13
19
|
console.warn(chalk.redBright("Cannot send email, invalid SMTP settings."));
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import ui from "@joystick.js/ui";
|
|
2
2
|
const ResetPassword = ui.component({
|
|
3
|
-
id: process.env.NODE_ENV === "test" ? "testComponent1234" : null,
|
|
4
3
|
render: ({ props }) => {
|
|
5
4
|
return `
|
|
6
5
|
<p>A password reset was requested for this email address (${props.emailAddress}). If you requested this reset, click the link below to reset your password:</p>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
class Fixture {
|
|
2
|
+
constructor(options = {}) {
|
|
3
|
+
this.options = options;
|
|
4
|
+
this.quantity = options?.quantity;
|
|
5
|
+
this.run = this.run.bind(this);
|
|
6
|
+
return this.run;
|
|
7
|
+
}
|
|
8
|
+
async run(input = {}) {
|
|
9
|
+
this.input = input;
|
|
10
|
+
const skip = typeof this?.options?.skip === "function" ? await this.options.skip(this, input) : false;
|
|
11
|
+
let dataToCreate = [];
|
|
12
|
+
if (!skip) {
|
|
13
|
+
dataToCreate = await this.generateDataToCreate(input);
|
|
14
|
+
if (typeof this?.options?.onCreate === "function") {
|
|
15
|
+
await this.options.onCreate(this, dataToCreate, (onAfterCreateEachInput = {}) => {
|
|
16
|
+
return this?.options?.onAfterCreateEach(this, onAfterCreateEachInput, input);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (typeof this?.options?.onAfterCreateAll === "function") {
|
|
21
|
+
this.options.onAfterCreateAll(this, dataToCreate, input);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async generateDataToCreate(input = {}) {
|
|
25
|
+
const data = [];
|
|
26
|
+
for (let i = 0; i < this?.quantity; i += 1) {
|
|
27
|
+
if (typeof this?.options?.template === "function") {
|
|
28
|
+
const dataToCreate = await this.options?.template(this, i, input);
|
|
29
|
+
data.push(dataToCreate);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return data;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
var fixture_default = (options = {}) => {
|
|
36
|
+
return new Fixture(options);
|
|
37
|
+
};
|
|
38
|
+
export {
|
|
39
|
+
fixture_default as default
|
|
40
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -4,22 +4,29 @@ import { dirname } from "path";
|
|
|
4
4
|
import sanitizeHTML from "sanitize-html";
|
|
5
5
|
import _accounts from "./app/accounts";
|
|
6
6
|
import _action from "./action/index.js";
|
|
7
|
+
import _fixture from "./fixture/index.js";
|
|
8
|
+
import _test from "./test/index.js";
|
|
7
9
|
import _websockets from "./websockets";
|
|
8
10
|
import api from "./api/index.js";
|
|
9
11
|
import app from "./app/index.js";
|
|
10
12
|
import generateId from "./lib/generateId.js";
|
|
13
|
+
import _generate_sql_from_object from "./app/databases/generate_sql_from_object";
|
|
11
14
|
import getOrigin from "./api/getOrigin";
|
|
12
15
|
import loadSettings from "./settings/load";
|
|
13
16
|
import pushLogs from "./push/logs/index.js";
|
|
14
17
|
import nodeUrlPolyfills from "./lib/nodeUrlPolyfills.js";
|
|
15
18
|
import sendEmail from "./email/send";
|
|
19
|
+
const { readFile } = fs.promises;
|
|
16
20
|
if (process.env.NODE_ENV !== "development" && process.env.IS_PUSH_DEPLOYED) {
|
|
17
21
|
pushLogs();
|
|
18
22
|
}
|
|
23
|
+
const generate_sql_from_object = _generate_sql_from_object;
|
|
19
24
|
const accounts = _accounts;
|
|
20
25
|
const action = _action;
|
|
26
|
+
const fixture = _fixture;
|
|
21
27
|
const get = api.get;
|
|
22
28
|
const set = api.set;
|
|
29
|
+
const test = _test;
|
|
23
30
|
const email = {
|
|
24
31
|
send: sendEmail
|
|
25
32
|
};
|
|
@@ -36,6 +43,11 @@ const __dirname = nodeUrlPolyfills.__dirname;
|
|
|
36
43
|
const id = generateId;
|
|
37
44
|
const origin = getOrigin();
|
|
38
45
|
const settings = loadSettings();
|
|
46
|
+
const push = {
|
|
47
|
+
continent: fs.existsSync("/root/push/continent.txt") ? (await readFile("/root/push/continent.txt", "utf-8"))?.replace("\n", "") : null,
|
|
48
|
+
instance_token: fs.existsSync("/root/push/instance_token.txt") ? (await readFile("/root/push/instance_token.txt", "utf-8"))?.replace("\n", "") : null,
|
|
49
|
+
current_version: fs.existsSync("/root/push/versions/current") ? (await readFile("/root/push/versions/current", "utf-8"))?.replace("\n", "") : null
|
|
50
|
+
};
|
|
39
51
|
global.joystick = {
|
|
40
52
|
id: generateId,
|
|
41
53
|
emitters: {},
|
|
@@ -51,9 +63,12 @@ var src_default = {
|
|
|
51
63
|
action,
|
|
52
64
|
app,
|
|
53
65
|
email,
|
|
66
|
+
fixture,
|
|
67
|
+
generate_sql_from_object,
|
|
54
68
|
get,
|
|
55
69
|
id,
|
|
56
70
|
origin,
|
|
71
|
+
push,
|
|
57
72
|
sanitize,
|
|
58
73
|
set,
|
|
59
74
|
settings,
|
|
@@ -67,10 +82,14 @@ export {
|
|
|
67
82
|
action,
|
|
68
83
|
src_default as default,
|
|
69
84
|
email,
|
|
85
|
+
fixture,
|
|
86
|
+
generate_sql_from_object,
|
|
70
87
|
get,
|
|
71
88
|
id,
|
|
72
89
|
origin,
|
|
90
|
+
push,
|
|
73
91
|
sanitize,
|
|
74
92
|
set,
|
|
93
|
+
test,
|
|
75
94
|
websockets
|
|
76
95
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import escapeHTML from "./escapeHTML.js";
|
|
2
|
+
var escapeKeyValuePair_default = (target = {}) => {
|
|
3
|
+
const parameters = Object.entries(target || {});
|
|
4
|
+
for (let i = 0; i < parameters?.length; i += 1) {
|
|
5
|
+
const [key, value] = parameters[i];
|
|
6
|
+
delete target[key];
|
|
7
|
+
target[escapeHTML(key)] = escapeHTML(value);
|
|
8
|
+
}
|
|
9
|
+
return target;
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
escapeKeyValuePair_default as default
|
|
13
|
+
};
|
package/dist/lib/getBuildPath.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
var getBuildPath_default = () => {
|
|
3
|
-
if (process.env.NODE_ENV
|
|
3
|
+
if (["development", "test"].includes(process.env.NODE_ENV) || fs.existsSync(".joystick/build")) {
|
|
4
4
|
return ".joystick/build/";
|
|
5
5
|
}
|
|
6
6
|
return "";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
var getSSLCertificates_default = (ssl = null) => {
|
|
3
|
-
const pushCertificatePath = "/
|
|
4
|
-
const pushKeyPath = "/
|
|
3
|
+
const pushCertificatePath = "/root/push/certs/cert.pem";
|
|
4
|
+
const pushKeyPath = "/root/push/certs/key.pem";
|
|
5
5
|
const certPath = process.env.IS_PUSH_DEPLOYED ? pushCertificatePath : ssl?.cert || null;
|
|
6
6
|
const keyPath = process.env.IS_PUSH_DEPLOYED ? pushKeyPath : ssl?.key || null;
|
|
7
7
|
const certExists = fs.existsSync(certPath);
|
|
8
8
|
const keyExists = fs.existsSync(keyPath);
|
|
9
|
-
if (process.env.NODE_ENV
|
|
9
|
+
if (["development", "test"].includes(process.env.NODE_ENV) || !certExists || !keyExists) {
|
|
10
10
|
return null;
|
|
11
11
|
}
|
|
12
12
|
return {
|
package/dist/lib/log.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isObject } from "../validation/lib/typeValidators";
|
|
2
2
|
import camelPascalToSnake from "./camelPascalToSnake";
|
|
3
3
|
const objectToSQLKeys = (objectToConvert = {}, target = []) => {
|
|
4
|
-
const keyValuePairs = Object.entries(objectToConvert);
|
|
4
|
+
const keyValuePairs = Object.entries(objectToConvert || {});
|
|
5
5
|
keyValuePairs.forEach(([key, value]) => {
|
|
6
6
|
if (isObject(value)) {
|
|
7
7
|
target.push(camelPascalToSnake(key));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isObject } from "../validation/lib/typeValidators";
|
|
2
2
|
const objectToSQLValues = (objectToConvert = {}, target = []) => {
|
|
3
|
-
const keyValuePairs = Object.entries(objectToConvert);
|
|
3
|
+
const keyValuePairs = Object.entries(objectToConvert || {});
|
|
4
4
|
keyValuePairs.forEach(([_key, value]) => {
|
|
5
5
|
if (isObject(value)) {
|
|
6
6
|
objectToSQLValues(value, target);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
var timestamps_default = {
|
|
2
|
+
get_current_time: (options2 = {}) => {
|
|
3
|
+
const timestamp = new Date().toISOString();
|
|
4
|
+
return options2?.mongodb_ttl ? new Date(timestamp) : timestamp;
|
|
5
|
+
},
|
|
6
|
+
get_future_time: (unit = "", quantity = 0, options2 = {}) => {
|
|
7
|
+
const date = new Date();
|
|
8
|
+
switch (unit) {
|
|
9
|
+
case "seconds":
|
|
10
|
+
date.setSeconds(date.getSeconds() + quantity);
|
|
11
|
+
return options2?.mongodb_ttl ? new Date(date.toISOString()) : date.toISOString();
|
|
12
|
+
case "minutes":
|
|
13
|
+
date.setMinutes(date.getMinutes() + quantity);
|
|
14
|
+
return options2?.mongodb_ttl ? new Date(date.toISOString()) : date.toISOString();
|
|
15
|
+
case "hours":
|
|
16
|
+
date.setHours(date.getHours() + quantity);
|
|
17
|
+
return options2?.mongodb_ttl ? new Date(date.toISOString()) : date.toISOString();
|
|
18
|
+
case "days":
|
|
19
|
+
date.setHours(date.getHours() + quantity * 24);
|
|
20
|
+
return options2?.mongodb_ttl ? new Date(date.toISOString()) : date.toISOString();
|
|
21
|
+
default:
|
|
22
|
+
return options2?.mongodb_ttl ? new Date(date.toISOString()) : date.toISOString();
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
get_past_time: (unit = "", quantity = 0) => {
|
|
26
|
+
const date = new Date();
|
|
27
|
+
switch (unit) {
|
|
28
|
+
case "seconds":
|
|
29
|
+
date.setSeconds(date.getSeconds() - quantity);
|
|
30
|
+
return options?.mongodb_ttl ? new Date(date.toISOString()) : date.toISOString();
|
|
31
|
+
case "minutes":
|
|
32
|
+
date.setMinutes(date.getMinutes() - quantity);
|
|
33
|
+
return options?.mongodb_ttl ? new Date(date.toISOString()) : date.toISOString();
|
|
34
|
+
case "hours":
|
|
35
|
+
date.setHours(date.getHours() - quantity);
|
|
36
|
+
return options?.mongodb_ttl ? new Date(date.toISOString()) : date.toISOString();
|
|
37
|
+
case "days":
|
|
38
|
+
date.setHours(date.getHours() - quantity * 24);
|
|
39
|
+
return options?.mongodb_ttl ? new Date(date.toISOString()) : date.toISOString();
|
|
40
|
+
default:
|
|
41
|
+
return options?.mongodb_ttl ? new Date(new Date().toISOString()) : new Date().toISOString();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
export {
|
|
46
|
+
timestamps_default as default
|
|
47
|
+
};
|
package/dist/lib/wait.js
ADDED
package/dist/push/logs/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { MongoClient } from "mongodb";
|
|
2
|
+
import timestamps from "../../lib/timestamps";
|
|
3
|
+
const KILOBYTE = 1e3;
|
|
4
|
+
const MEGABYTE = KILOBYTE * 1e3;
|
|
3
5
|
const captureLog = (callback = null) => {
|
|
4
6
|
process.stdout.write = (data) => {
|
|
5
7
|
if (callback) {
|
|
@@ -13,35 +15,51 @@ const captureLog = (callback = null) => {
|
|
|
13
15
|
};
|
|
14
16
|
process.on("uncaughtException", (error) => {
|
|
15
17
|
if (callback) {
|
|
16
|
-
callback("uncaughtException", error);
|
|
18
|
+
callback("uncaughtException", error?.message || "Uncaught Exception");
|
|
17
19
|
}
|
|
18
20
|
});
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
file: {
|
|
23
|
-
development: "logs.json",
|
|
24
|
-
production: "/root/logs.json"
|
|
25
|
-
}[process.env.NODE_ENV || "development"],
|
|
26
|
-
collections: {
|
|
27
|
-
logs: []
|
|
21
|
+
process.on("unhandledRejection", (error) => {
|
|
22
|
+
if (callback) {
|
|
23
|
+
callback("unhandledRejection", error?.message || "Unhandled Rejection");
|
|
28
24
|
}
|
|
29
25
|
});
|
|
30
|
-
|
|
26
|
+
};
|
|
27
|
+
const connectMongoDB = async () => {
|
|
28
|
+
const client = new MongoClient("mongodb://localhost:27017");
|
|
29
|
+
const db = client.db("push");
|
|
30
|
+
try {
|
|
31
|
+
await db.createCollection("logs", { capped: true, size: MEGABYTE * 50, max: 1e3 });
|
|
32
|
+
await db.createCollection("metrics", { capped: true, size: MEGABYTE * 50, max: 1e3 });
|
|
33
|
+
} catch {
|
|
34
|
+
}
|
|
35
|
+
await client.connect();
|
|
36
|
+
return {
|
|
37
|
+
client,
|
|
38
|
+
db
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
const writeLogsToDisk = () => {
|
|
42
|
+
captureLog(async (source = "", data = "") => {
|
|
43
|
+
const mongodb = await connectMongoDB();
|
|
31
44
|
switch (source) {
|
|
32
45
|
case "stdout":
|
|
33
|
-
|
|
46
|
+
await mongodb.db.collection("logs").insertOne({
|
|
34
47
|
error: false,
|
|
35
|
-
timestamp:
|
|
48
|
+
timestamp: timestamps.get_current_time(),
|
|
49
|
+
process_id: process.pid,
|
|
36
50
|
data
|
|
37
51
|
});
|
|
52
|
+
return mongodb.client.close();
|
|
38
53
|
case "stderr":
|
|
39
54
|
case "uncaughtException":
|
|
40
|
-
|
|
55
|
+
case "unhandledRejection":
|
|
56
|
+
await mongodb.db.collection("logs").insertOne({
|
|
41
57
|
error: true,
|
|
42
|
-
timestamp:
|
|
58
|
+
timestamp: timestamps.get_current_time(),
|
|
59
|
+
process_id: process.pid,
|
|
43
60
|
data
|
|
44
61
|
});
|
|
62
|
+
return mongodb.client.close();
|
|
45
63
|
default:
|
|
46
64
|
return;
|
|
47
65
|
}
|
package/dist/settings/load.js
CHANGED
package/dist/ssr/compileCSS.js
CHANGED
|
@@ -30,7 +30,7 @@ var compileCSS_default = (css = "", componentInstance = {}) => {
|
|
|
30
30
|
`;
|
|
31
31
|
}
|
|
32
32
|
if (hasMinRules && hasMinWidthRules) {
|
|
33
|
-
const minWidthRules = Object.entries(css?.min?.width);
|
|
33
|
+
const minWidthRules = Object.entries(css?.min?.width || {});
|
|
34
34
|
for (let i = 0; i < minWidthRules.length; i += 1) {
|
|
35
35
|
const [minWidth, minWidthRule] = minWidthRules[i];
|
|
36
36
|
compiledCSS += `
|
|
@@ -41,7 +41,7 @@ var compileCSS_default = (css = "", componentInstance = {}) => {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
if (hasMinRules && hasMinHeightRules) {
|
|
44
|
-
const minHeightRules = Object.entries(css?.min?.height);
|
|
44
|
+
const minHeightRules = Object.entries(css?.min?.height || {});
|
|
45
45
|
for (let i = 0; i < minHeightRules.length; i += 1) {
|
|
46
46
|
const [minHeight, minHeightRule] = minHeightRules[i];
|
|
47
47
|
compiledCSS += `
|
|
@@ -52,7 +52,7 @@ var compileCSS_default = (css = "", componentInstance = {}) => {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
if (hasMaxRules && hasMaxWidthRules) {
|
|
55
|
-
const maxWidthRules = Object.entries(css?.max?.width);
|
|
55
|
+
const maxWidthRules = Object.entries(css?.max?.width || {});
|
|
56
56
|
for (let i = 0; i < maxWidthRules.length; i += 1) {
|
|
57
57
|
const [maxWidth, maxWidthRule] = maxWidthRules[i];
|
|
58
58
|
compiledCSS += `
|
|
@@ -63,7 +63,7 @@ var compileCSS_default = (css = "", componentInstance = {}) => {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
if (hasMaxRules && hasMaxHeightRules) {
|
|
66
|
-
const maxHeightRules = Object.entries(css?.max?.height);
|
|
66
|
+
const maxHeightRules = Object.entries(css?.max?.height || {});
|
|
67
67
|
for (let i = 0; i < maxHeightRules.length; i += 1) {
|
|
68
68
|
const [maxHeight, maxHeightRule] = maxHeightRules[i];
|
|
69
69
|
compiledCSS += `
|
|
@@ -4,7 +4,7 @@ const isObject = (value) => {
|
|
|
4
4
|
const findComponentInTree = (tree = {}, componentId = "", callback = {}) => {
|
|
5
5
|
const isTree = tree && tree.id;
|
|
6
6
|
if (isObject(tree) && isTree) {
|
|
7
|
-
const entries = Object.entries(tree);
|
|
7
|
+
const entries = Object.entries(tree || {});
|
|
8
8
|
for (let i = 0; i < entries.length; i += 1) {
|
|
9
9
|
const [treeKey, treeValue] = entries[i];
|
|
10
10
|
if (treeKey === "id" && treeValue === componentId) {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import get from "../api/get";
|
|
2
|
+
import set from "../api/set";
|
|
3
|
+
var getAPIForDataFunctions_default = (req = {}, api = {}) => {
|
|
4
|
+
try {
|
|
5
|
+
return {
|
|
6
|
+
get: (getterName = "", getterOptions = {}) => {
|
|
7
|
+
return get({
|
|
8
|
+
getterName,
|
|
9
|
+
getterOptions: api?.getters[getterName] || {},
|
|
10
|
+
skip: getterOptions?.skip,
|
|
11
|
+
input: getterOptions?.input,
|
|
12
|
+
output: getterOptions?.output,
|
|
13
|
+
context: req?.context,
|
|
14
|
+
APIOptions: api?.options
|
|
15
|
+
});
|
|
16
|
+
},
|
|
17
|
+
set: (setterName = "", setterOptions = {}) => {
|
|
18
|
+
return set({
|
|
19
|
+
setterName,
|
|
20
|
+
setterOptions: api?.setters[setterName] || {},
|
|
21
|
+
skip: setterOptions?.skip,
|
|
22
|
+
input: setterOptions?.input,
|
|
23
|
+
output: setterOptions?.output,
|
|
24
|
+
context: req?.context,
|
|
25
|
+
APIOptions: api?.options
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
} catch (exception) {
|
|
30
|
+
throw new Error(`[ssr.getAPIForDataFunctions] ${exception.message}`);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
export {
|
|
34
|
+
getAPIForDataFunctions_default as default
|
|
35
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var getDataFromComponent_default = async (componentInstance = {}, api = {}, browserSafeUser = {}, browserSafeRequest = {}) => {
|
|
2
|
+
try {
|
|
3
|
+
componentInstance.user = browserSafeUser;
|
|
4
|
+
const data = await componentInstance.handleFetchData(api, browserSafeRequest, {}, componentInstance);
|
|
5
|
+
return {
|
|
6
|
+
componentId: componentInstance?.id,
|
|
7
|
+
data
|
|
8
|
+
};
|
|
9
|
+
} catch (exception) {
|
|
10
|
+
throw new Error(`[ssr.getDataFromComponent] ${exception.message}`);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
export {
|
|
14
|
+
getDataFromComponent_default as default
|
|
15
|
+
};
|