@moreapp/common-nodejs 0.7.15 → 0.8.0
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/README.md +2 -2
- package/dist/MoreAppClient.d.ts +1 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.js +79 -4
- package/dist/utils.test.js +46 -0
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -34,8 +34,8 @@ And then use the `--require` [Node.js CLI option](https://nodejs.org/api/cli.htm
|
|
|
34
34
|
|
|
35
35
|
Follow the steps below to create a new release:
|
|
36
36
|
|
|
37
|
-
1. Ensure that the `master` branch has the commits you want to release
|
|
38
|
-
2. Start a new build in
|
|
37
|
+
1. Ensure that the (upstream) `master` branch has the commits you want to release
|
|
38
|
+
2. Start a new build in GitHub actions for the `master` branch with the `Publish` workflow
|
|
39
39
|
3. Select which type of version bump you want to do
|
|
40
40
|
4. The build will automatically create a new version and publish it to NPM
|
|
41
41
|
|
package/dist/MoreAppClient.d.ts
CHANGED
package/dist/utils.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { FormVersionField } from "./types";
|
|
1
2
|
export declare function environmentVariable(key: string): string;
|
|
2
3
|
export declare function environmentVariable(key: string, fallback: string): string;
|
|
3
4
|
export declare function environmentVariable(key: string, fallback: number): number;
|
|
4
5
|
export declare function environmentVariable(key: string, fallback: boolean): boolean;
|
|
5
6
|
export declare function currentTraceId(): string | undefined;
|
|
6
7
|
export declare function isValidEmail(email: string): boolean;
|
|
8
|
+
export declare function parseDynamicRecipients(dynamicRecipients: string[], fields: FormVersionField[], data: Record<string, unknown>): string[];
|
|
9
|
+
export declare function getDataForDataName(data: Record<string, unknown>, dataName: string | undefined): unknown | null;
|
package/dist/utils.js
CHANGED
|
@@ -1,11 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
4
24
|
};
|
|
5
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.isValidEmail = exports.currentTraceId = exports.environmentVariable = void 0;
|
|
26
|
+
exports.getDataForDataName = exports.parseDynamicRecipients = exports.isValidEmail = exports.currentTraceId = exports.environmentVariable = void 0;
|
|
7
27
|
const api_1 = require("@opentelemetry/api");
|
|
8
|
-
const lodash_1 =
|
|
28
|
+
const lodash_1 = __importStar(require("lodash"));
|
|
9
29
|
function environmentVariable(key, fallback) {
|
|
10
30
|
const value = process.env[key] || fallback;
|
|
11
31
|
if (value === undefined) {
|
|
@@ -54,3 +74,58 @@ function isValidEmail(email) {
|
|
|
54
74
|
emailAddressDomainPattern.test(domain));
|
|
55
75
|
}
|
|
56
76
|
exports.isValidEmail = isValidEmail;
|
|
77
|
+
function parseDynamicRecipients(dynamicRecipients, fields, data) {
|
|
78
|
+
const recipients = [];
|
|
79
|
+
dynamicRecipients.forEach((fieldUid) => {
|
|
80
|
+
if (!fieldUid) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
let dataName;
|
|
84
|
+
if (fieldUid.includes(".")) {
|
|
85
|
+
// column in Search-widget, like: "<field-uid>.email"
|
|
86
|
+
const parts = fieldUid.split(".");
|
|
87
|
+
dataName = [getDataNameForFieldUid(fields, parts[0]), parts[1]].join(".");
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
dataName = getDataNameForFieldUid(fields, fieldUid);
|
|
91
|
+
}
|
|
92
|
+
if (dataName) {
|
|
93
|
+
const fieldData = getDataForDataName(data, dataName);
|
|
94
|
+
if (fieldData && Array.isArray(fieldData)) {
|
|
95
|
+
// like multiple Lookup-widget
|
|
96
|
+
fieldData.forEach(function (dataFieldEntry) {
|
|
97
|
+
if (typeof dataFieldEntry === "string" && isValidEmail(dataFieldEntry.trim())) {
|
|
98
|
+
recipients.push(dataFieldEntry.trim());
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
else if (typeof fieldData === "string" && isValidEmail(fieldData.trim())) {
|
|
103
|
+
recipients.push(fieldData.trim());
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
return recipients;
|
|
108
|
+
}
|
|
109
|
+
exports.parseDynamicRecipients = parseDynamicRecipients;
|
|
110
|
+
function getDataNameForFieldUid(fields, fieldUid) {
|
|
111
|
+
return fields.find((field) => field.uid === fieldUid)?.properties.data_name;
|
|
112
|
+
}
|
|
113
|
+
function getDataForDataName(data, dataName) {
|
|
114
|
+
if (!dataName || !data) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
// resolve nested field (like: SEARCH_FIELD.name)
|
|
118
|
+
if (dataName.includes(".")) {
|
|
119
|
+
const parts = dataName.split(".");
|
|
120
|
+
let nestedData = data[parts[0]];
|
|
121
|
+
if (isObject(nestedData)) {
|
|
122
|
+
const nestedKey = parts.slice(1).join(".");
|
|
123
|
+
return getDataForDataName(nestedData, nestedKey);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return data[dataName];
|
|
127
|
+
}
|
|
128
|
+
exports.getDataForDataName = getDataForDataName;
|
|
129
|
+
function isObject(data) {
|
|
130
|
+
return (0, lodash_1.isPlainObject)(data);
|
|
131
|
+
}
|
package/dist/utils.test.js
CHANGED
|
@@ -63,3 +63,49 @@ describe("isValidEmail", () => {
|
|
|
63
63
|
test("Local part contains whitespace", () => expect((0, utils_1.isValidEmail)("a b@moreapp.dev")).toBeFalsy());
|
|
64
64
|
});
|
|
65
65
|
});
|
|
66
|
+
describe("parseDynamicRecipients", () => {
|
|
67
|
+
test("should parse all type of data (root, object, array)", () => {
|
|
68
|
+
const fields = [
|
|
69
|
+
{ uid: "UID-root", properties: { data_name: "customer" } },
|
|
70
|
+
{ uid: "UID-object", properties: { data_name: "vendor" } },
|
|
71
|
+
{ uid: "UID-array", properties: { data_name: "contacts" } },
|
|
72
|
+
];
|
|
73
|
+
expect((0, utils_1.parseDynamicRecipients)(["UID-root", "UID-object.email", "UID-array"], fields, {
|
|
74
|
+
customer: "customer@example.com",
|
|
75
|
+
vendor: { id: 1, email: "vendor@example.com" },
|
|
76
|
+
contacts: ["contact1@example.com", "contact2@example.com"],
|
|
77
|
+
})).toEqual([
|
|
78
|
+
"customer@example.com",
|
|
79
|
+
"vendor@example.com",
|
|
80
|
+
"contact1@example.com",
|
|
81
|
+
"contact2@example.com",
|
|
82
|
+
]);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
describe("getDataForDataName", () => {
|
|
86
|
+
test("should return (nested) values in objects based on dataName", () => {
|
|
87
|
+
let data = {
|
|
88
|
+
name: "John",
|
|
89
|
+
age: 10,
|
|
90
|
+
address: {
|
|
91
|
+
street: "Main Street",
|
|
92
|
+
city: "New York",
|
|
93
|
+
location: {
|
|
94
|
+
longitude: 10,
|
|
95
|
+
latitude: 10,
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
"flat.test": "hi",
|
|
99
|
+
};
|
|
100
|
+
expect((0, utils_1.getDataForDataName)(data, "name")).toBe("John");
|
|
101
|
+
expect((0, utils_1.getDataForDataName)(data, "age")).toBe(10);
|
|
102
|
+
expect((0, utils_1.getDataForDataName)(data, "address.city")).toBe("New York");
|
|
103
|
+
expect((0, utils_1.getDataForDataName)(data, "address.location.longitude")).toBe(10);
|
|
104
|
+
expect((0, utils_1.getDataForDataName)(data, "flat.test")).toBe("hi");
|
|
105
|
+
expect((0, utils_1.getDataForDataName)(data, "unknown")).toBe(undefined);
|
|
106
|
+
expect((0, utils_1.getDataForDataName)(data, "unknown.nested")).toBe(undefined);
|
|
107
|
+
expect((0, utils_1.getDataForDataName)(data, "address.unknown")).toBe(undefined);
|
|
108
|
+
expect((0, utils_1.getDataForDataName)(data, "flat..")).toBe(undefined);
|
|
109
|
+
expect((0, utils_1.getDataForDataName)(data, ".")).toBe(undefined);
|
|
110
|
+
});
|
|
111
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moreapp/common-nodejs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"dist/**/*"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@google-cloud/logging": "
|
|
22
|
+
"@google-cloud/logging": "11.2.0",
|
|
23
23
|
"@google-cloud/opentelemetry-cloud-trace-exporter": "2.1.0",
|
|
24
24
|
"@opentelemetry/api": "1.8.0",
|
|
25
25
|
"@opentelemetry/core": "1.22.0",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"@opentelemetry/sdk-trace-base": "1.22.0",
|
|
34
34
|
"@opentelemetry/sdk-trace-node": "1.22.0",
|
|
35
35
|
"@opentelemetry/semantic-conventions": "1.22.0",
|
|
36
|
-
"axios": "1.
|
|
36
|
+
"axios": "1.8.2",
|
|
37
37
|
"content-disposition-parser": "1.0.2",
|
|
38
38
|
"date-and-time": "3.1.1",
|
|
39
39
|
"lodash": "4.17.21",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/jest": "29.5.11",
|
|
45
45
|
"@types/lodash": "4.17.0",
|
|
46
|
-
"@types/node": "
|
|
46
|
+
"@types/node": "22.16.2",
|
|
47
47
|
"@typescript-eslint/eslint-plugin": "6.21.0",
|
|
48
48
|
"@typescript-eslint/parser": "6.21.0",
|
|
49
49
|
"eslint": "8.57.0",
|