@moreapp/common-nodejs 0.7.4 → 0.7.6

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/dist/schema.d.ts CHANGED
@@ -75,7 +75,8 @@ export declare const SubmissionSchema: z.ZodObject<{
75
75
  }>;
76
76
  meta: z.ZodObject<{
77
77
  registrationDate: z.ZodString;
78
- instructionId: z.ZodNullable<z.ZodString>;
78
+ instructionId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
79
+ taskId: z.ZodNullable<z.ZodString>;
79
80
  serialNumber: z.ZodNumber;
80
81
  guid: z.ZodString;
81
82
  location: z.ZodNullable<z.ZodObject<{
@@ -90,22 +91,24 @@ export declare const SubmissionSchema: z.ZodObject<{
90
91
  }>>;
91
92
  }, "strip", z.ZodTypeAny, {
92
93
  registrationDate: string;
93
- instructionId: string | null;
94
+ taskId: string | null;
94
95
  serialNumber: number;
95
96
  guid: string;
96
97
  location: {
97
98
  longitude: string;
98
99
  latitude: string;
99
100
  } | null;
101
+ instructionId?: string | null | undefined;
100
102
  }, {
101
103
  registrationDate: string;
102
- instructionId: string | null;
104
+ taskId: string | null;
103
105
  serialNumber: number;
104
106
  guid: string;
105
107
  location: {
106
108
  longitude: string;
107
109
  latitude: string;
108
110
  } | null;
111
+ instructionId?: string | null | undefined;
109
112
  }>;
110
113
  data: z.ZodRecord<z.ZodString, z.ZodAny>;
111
114
  mailStatuses: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
@@ -129,13 +132,14 @@ export declare const SubmissionSchema: z.ZodObject<{
129
132
  };
130
133
  meta: {
131
134
  registrationDate: string;
132
- instructionId: string | null;
135
+ taskId: string | null;
133
136
  serialNumber: number;
134
137
  guid: string;
135
138
  location: {
136
139
  longitude: string;
137
140
  latitude: string;
138
141
  } | null;
142
+ instructionId?: string | null | undefined;
139
143
  };
140
144
  mailStatuses?: {
141
145
  emailAddresses: string[];
@@ -152,13 +156,14 @@ export declare const SubmissionSchema: z.ZodObject<{
152
156
  };
153
157
  meta: {
154
158
  registrationDate: string;
155
- instructionId: string | null;
159
+ taskId: string | null;
156
160
  serialNumber: number;
157
161
  guid: string;
158
162
  location: {
159
163
  longitude: string;
160
164
  latitude: string;
161
165
  } | null;
166
+ instructionId?: string | null | undefined;
162
167
  };
163
168
  mailStatuses?: {
164
169
  emailAddresses: string[];
@@ -222,7 +227,8 @@ export declare const BaseIntegrationRequestSchema: z.ZodObject<{
222
227
  }>;
223
228
  meta: z.ZodObject<{
224
229
  registrationDate: z.ZodString;
225
- instructionId: z.ZodNullable<z.ZodString>;
230
+ instructionId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
231
+ taskId: z.ZodNullable<z.ZodString>;
226
232
  serialNumber: z.ZodNumber;
227
233
  guid: z.ZodString;
228
234
  location: z.ZodNullable<z.ZodObject<{
@@ -237,22 +243,24 @@ export declare const BaseIntegrationRequestSchema: z.ZodObject<{
237
243
  }>>;
238
244
  }, "strip", z.ZodTypeAny, {
239
245
  registrationDate: string;
240
- instructionId: string | null;
246
+ taskId: string | null;
241
247
  serialNumber: number;
242
248
  guid: string;
243
249
  location: {
244
250
  longitude: string;
245
251
  latitude: string;
246
252
  } | null;
253
+ instructionId?: string | null | undefined;
247
254
  }, {
248
255
  registrationDate: string;
249
- instructionId: string | null;
256
+ taskId: string | null;
250
257
  serialNumber: number;
251
258
  guid: string;
252
259
  location: {
253
260
  longitude: string;
254
261
  latitude: string;
255
262
  } | null;
263
+ instructionId?: string | null | undefined;
256
264
  }>;
257
265
  data: z.ZodRecord<z.ZodString, z.ZodAny>;
258
266
  mailStatuses: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
@@ -276,13 +284,14 @@ export declare const BaseIntegrationRequestSchema: z.ZodObject<{
276
284
  };
277
285
  meta: {
278
286
  registrationDate: string;
279
- instructionId: string | null;
287
+ taskId: string | null;
280
288
  serialNumber: number;
281
289
  guid: string;
282
290
  location: {
283
291
  longitude: string;
284
292
  latitude: string;
285
293
  } | null;
294
+ instructionId?: string | null | undefined;
286
295
  };
287
296
  mailStatuses?: {
288
297
  emailAddresses: string[];
@@ -299,13 +308,14 @@ export declare const BaseIntegrationRequestSchema: z.ZodObject<{
299
308
  };
300
309
  meta: {
301
310
  registrationDate: string;
302
- instructionId: string | null;
311
+ taskId: string | null;
303
312
  serialNumber: number;
304
313
  guid: string;
305
314
  location: {
306
315
  longitude: string;
307
316
  latitude: string;
308
317
  } | null;
318
+ instructionId?: string | null | undefined;
309
319
  };
310
320
  mailStatuses?: {
311
321
  emailAddresses: string[];
@@ -341,13 +351,14 @@ export declare const BaseIntegrationRequestSchema: z.ZodObject<{
341
351
  };
342
352
  meta: {
343
353
  registrationDate: string;
344
- instructionId: string | null;
354
+ taskId: string | null;
345
355
  serialNumber: number;
346
356
  guid: string;
347
357
  location: {
348
358
  longitude: string;
349
359
  latitude: string;
350
360
  } | null;
361
+ instructionId?: string | null | undefined;
351
362
  };
352
363
  mailStatuses?: {
353
364
  emailAddresses: string[];
@@ -379,13 +390,14 @@ export declare const BaseIntegrationRequestSchema: z.ZodObject<{
379
390
  };
380
391
  meta: {
381
392
  registrationDate: string;
382
- instructionId: string | null;
393
+ taskId: string | null;
383
394
  serialNumber: number;
384
395
  guid: string;
385
396
  location: {
386
397
  longitude: string;
387
398
  latitude: string;
388
399
  } | null;
400
+ instructionId?: string | null | undefined;
389
401
  };
390
402
  mailStatuses?: {
391
403
  emailAddresses: string[];
package/dist/schema.js CHANGED
@@ -21,7 +21,8 @@ exports.SubmissionSchema = zod_1.z.object({
21
21
  }),
22
22
  meta: zod_1.z.object({
23
23
  registrationDate: zod_1.z.string(),
24
- instructionId: zod_1.z.string().nullable(),
24
+ instructionId: zod_1.z.string().nullable().optional().describe("DEPRECATED - Use 'taskId' instead"),
25
+ taskId: zod_1.z.string().nullable(),
25
26
  serialNumber: zod_1.z.number(),
26
27
  guid: zod_1.z.string(),
27
28
  location: zod_1.z
package/dist/tracer.js CHANGED
@@ -41,7 +41,7 @@ const tracer = (serviceName, { http = {
41
41
  injectEncoding: propagator_b3_1.B3InjectEncoding.MULTI_HEADER,
42
42
  }),
43
43
  });
44
- if (process.env["STACKDRIVER_TRACING_ENABLED"] === "true") {
44
+ if ((0, utils_1.environmentVariable)("STACKDRIVER_TRACING_ENABLED", false)) {
45
45
  const exporter = new opentelemetry_cloud_trace_exporter_1.TraceExporter({
46
46
  resourceFilter: /^service\./,
47
47
  });
package/dist/utils.d.ts CHANGED
@@ -1,3 +1,6 @@
1
- export declare function environmentVariable(key: string, fallback?: string | number): string;
1
+ export declare function environmentVariable(key: string): string;
2
+ export declare function environmentVariable(key: string, fallback: string): string;
3
+ export declare function environmentVariable(key: string, fallback: number): number;
4
+ export declare function environmentVariable(key: string, fallback: boolean): boolean;
2
5
  export declare function currentTraceId(): string | undefined;
3
6
  export declare function isValidEmail(email: string): boolean;
package/dist/utils.js CHANGED
@@ -1,22 +1,53 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.isValidEmail = exports.currentTraceId = exports.environmentVariable = void 0;
4
7
  const context_utils_1 = require("@opentelemetry/api/build/src/trace/context-utils");
5
8
  const api_1 = require("@opentelemetry/api");
9
+ const lodash_1 = __importDefault(require("lodash"));
6
10
  function environmentVariable(key, fallback) {
7
11
  const value = process.env[key] || fallback;
8
- if (value) {
9
- return value.toString();
12
+ if (value === undefined) {
13
+ throw new Error(`Missing environment variable '${key}'`);
10
14
  }
11
- throw new Error(`Missing environment variable '${key}'`);
15
+ else if (fallback === undefined) {
16
+ return value;
17
+ }
18
+ else if (lodash_1.default.isString(fallback) && lodash_1.default.isString(value)) {
19
+ return value;
20
+ }
21
+ else if (lodash_1.default.isFinite(fallback) && lodash_1.default.isFinite(Number(value))) {
22
+ return Number(value);
23
+ }
24
+ else if (lodash_1.default.isBoolean(fallback) &&
25
+ (lodash_1.default.isBoolean(value) || value === "true" || value === "false")) {
26
+ return Boolean(value);
27
+ }
28
+ throw new Error(`Wrong type for environment variable '${key}'`);
12
29
  }
13
30
  exports.environmentVariable = environmentVariable;
14
31
  function currentTraceId() {
15
32
  return (0, context_utils_1.getSpanContext)(api_1.context.active())?.traceId;
16
33
  }
17
34
  exports.currentTraceId = currentTraceId;
18
- const validEmailPattern = /^[A-Z0-9._&%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i;
35
+ const emailAddressMaxLength = 254; // https://stackoverflow.com/a/574698
36
+ const emailAddressLocalPattern = /^.+$/;
37
+ const emailAddressDomainPattern = /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$/;
38
+ // There are many regex patterns to validate email addresses, but they all have flaws and cannot 100% correctly verify
39
+ // every possible email address. For us, it's more important to avoid the majority of typo's instead of catching every
40
+ // invalid email address. We let our email provider handle and false positives (either by their validation or the fact
41
+ // that the email could not be delivered.
42
+ // ! This code is duplicated in other projects, make sure that changes are made there too (including tests).
19
43
  function isValidEmail(email) {
20
- return validEmailPattern.test(email);
44
+ if (email.length > emailAddressMaxLength) {
45
+ return false;
46
+ }
47
+ const [localAddr, domain] = email.split("@");
48
+ if (localAddr === undefined || domain === undefined) {
49
+ return false;
50
+ }
51
+ return emailAddressLocalPattern.test(localAddr) && emailAddressDomainPattern.test(domain);
21
52
  }
22
53
  exports.isValidEmail = isValidEmail;
@@ -3,23 +3,58 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const utils_1 = require("./utils");
4
4
  describe("environmentVariable", () => {
5
5
  test("Should throw when environment variable does not exist", async () => {
6
- process.env["COMMONS_NODEJS_TEST_EXISTING"] = "SOME_VALUE";
7
- expect((0, utils_1.environmentVariable)("COMMONS_NODEJS_TEST_EXISTING")).toBe("SOME_VALUE");
6
+ expect(() => (0, utils_1.environmentVariable)("COMMONS_NODEJS_TEST_NON_EXISTING")).toThrow("Missing environment variable 'COMMONS_NODEJS_TEST_NON_EXISTING'");
8
7
  });
9
- test("Use fallback value when environment variable does not exist", async () => {
10
- expect((0, utils_1.environmentVariable)("COMMONS_NODEJS_TEST_NON_EXISTING", "DEFAULT_VALUE")).toBe("DEFAULT_VALUE");
8
+ test("Should return fallback value when environment variable does not exist (string)", async () => {
9
+ expect((0, utils_1.environmentVariable)("COMMONS_NODEJS_TEST_NON_EXISTING", "my-fallback")).toBe("my-fallback");
11
10
  });
12
- test("Should throw when environment variable does not exist", async () => {
13
- expect(() => (0, utils_1.environmentVariable)("COMMONS_NODEJS_TEST_NON_EXISTING")).toThrow("Missing environment variable 'COMMONS_NODEJS_TEST_NON_EXISTING'");
11
+ test("Should return fallback value when environment variable does not exist (number)", async () => {
12
+ expect((0, utils_1.environmentVariable)("COMMONS_NODEJS_TEST_NON_EXISTING", 1)).toBe(1);
13
+ });
14
+ test("Should return fallback value when environment variable does not exist (boolean)", async () => {
15
+ expect((0, utils_1.environmentVariable)("COMMONS_NODEJS_TEST_NON_EXISTING", false)).toBe(false);
16
+ });
17
+ test("Should return actual value when environment variable exists (string)", async () => {
18
+ process.env["COMMONS_NODEJS_TEST_EXISTING"] = "actual-value";
19
+ expect((0, utils_1.environmentVariable)("COMMONS_NODEJS_TEST_EXISTING", "my-fallback")).toBe("actual-value");
20
+ });
21
+ test("Should return actual value when environment variable exists (number)", async () => {
22
+ process.env["COMMONS_NODEJS_TEST_EXISTING"] = "2";
23
+ expect((0, utils_1.environmentVariable)("COMMONS_NODEJS_TEST_EXISTING", 1)).toBe(2);
24
+ });
25
+ test("Should return actual value when environment variable exists (boolean)", async () => {
26
+ process.env["COMMONS_NODEJS_TEST_EXISTING"] = "true";
27
+ expect((0, utils_1.environmentVariable)("COMMONS_NODEJS_TEST_EXISTING", false)).toBe(true);
28
+ });
29
+ test("should throw when environment variable contains an invalid type (number)", async () => {
30
+ process.env["COMMONS_NODEJS_TEST_EXISTING"] = "not-a-number";
31
+ expect(() => (0, utils_1.environmentVariable)("COMMONS_NODEJS_TEST_EXISTING", 1)).toThrow("Wrong type for environment variable 'COMMONS_NODEJS_TEST_EXISTING'");
32
+ });
33
+ test("should throw when environment variable contains an invalid type (boolean)", async () => {
34
+ process.env["COMMONS_NODEJS_TEST_EXISTING"] = "not-a-boolean";
35
+ expect(() => (0, utils_1.environmentVariable)("COMMONS_NODEJS_TEST_EXISTING", false)).toThrow("Wrong type for environment variable 'COMMONS_NODEJS_TEST_EXISTING'");
14
36
  });
15
37
  });
16
38
  describe("isValidEmail", () => {
17
- test("Should return true on valid email addresses", () => {
18
- expect((0, utils_1.isValidEmail)("john@example.com")).toBe(true);
19
- expect((0, utils_1.isValidEmail)("sbe-vsv.ch@schindler.com")).toEqual(true);
39
+ describe("Valid email addresses", () => {
40
+ test("Standard email address", () => expect((0, utils_1.isValidEmail)("a@moreapp.dev")).toBeTruthy());
41
+ test("Non-alphanumeric characters", () => expect((0, utils_1.isValidEmail)("a+-._&%'@moreapp.dev")).toBeTruthy());
42
+ test("Shortest email address", () => expect((0, utils_1.isValidEmail)("a@b.co")).toBeTruthy());
43
+ test("Subdomain", () => expect((0, utils_1.isValidEmail)("a@sub.domain.dev")).toBeTruthy());
44
+ test("Subdomain with a dash", () => expect((0, utils_1.isValidEmail)("a@sub.dom-ain.dev")).toBeTruthy());
45
+ test("Long TLD", () => expect((0, utils_1.isValidEmail)("a@b.business")).toBeTruthy());
46
+ test("Diacritics", () => expect((0, utils_1.isValidEmail)("ẞçäöü@moreapp.dev")).toBeTruthy());
20
47
  });
21
- test("Should return false on invalid email addresses", () => {
22
- expect((0, utils_1.isValidEmail)("john")).toBe(false);
23
- expect((0, utils_1.isValidEmail)("john@example")).toBe(false);
48
+ describe("Invalid email addresses", () => {
49
+ test("Missing '@' character and domain", () => expect((0, utils_1.isValidEmail)("john")).toBeFalsy());
50
+ test("// Multiple '@' characters", () => expect((0, utils_1.isValidEmail)("a@b@moreapp.dev")).toBeFalsy());
51
+ test("// Empty", () => expect((0, utils_1.isValidEmail)("")).toBeFalsy());
52
+ test("// Whitespace before/after", () => expect((0, utils_1.isValidEmail)(" a@moreapp.dev ")).toBeFalsy());
53
+ test("// Newlines, tabs, ..., before/after", () => expect((0, utils_1.isValidEmail)("\n \ta@moreapp.dev\n ")).toBeFalsy());
54
+ test("// Missing '@' character", () => expect((0, utils_1.isValidEmail)("ab.com")).toBeFalsy());
55
+ test("// Double dot in domain", () => expect((0, utils_1.isValidEmail)("a@moreapp..com")).toBeFalsy());
56
+ test("// Too short TLD", () => expect((0, utils_1.isValidEmail)("a@b.c")).toBeFalsy());
57
+ test("// Missing local part", () => expect((0, utils_1.isValidEmail)("@moreapp.dev")).toBeFalsy());
58
+ test("// Too long", () => expect((0, utils_1.isValidEmail)("abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz-abcdefghijklmnopqrstuvwxyz-@moreapp.dev")).toBeFalsy());
24
59
  });
25
60
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moreapp/common-nodejs",
3
- "version": "0.7.4",
3
+ "version": "0.7.6",
4
4
  "license": "UNLICENSED",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -18,42 +18,44 @@
18
18
  "dist/**/*"
19
19
  ],
20
20
  "dependencies": {
21
- "@google-cloud/logging": "10.4.1",
22
- "@google-cloud/opentelemetry-cloud-trace-exporter": "2.0.0",
21
+ "@google-cloud/logging": "10.5.0",
22
+ "@google-cloud/opentelemetry-cloud-trace-exporter": "2.1.0",
23
23
  "@opentelemetry/api": "1.4.1",
24
- "@opentelemetry/instrumentation": "0.38.0",
25
- "@opentelemetry/instrumentation-dns": "0.31.5",
26
- "@opentelemetry/instrumentation-express": "0.32.4",
27
- "@opentelemetry/instrumentation-http": "0.38.0",
28
- "@opentelemetry/instrumentation-winston": "0.31.4",
29
- "@opentelemetry/sdk-node": "0.38.0",
30
- "@opentelemetry/sdk-trace-node": "1.12.0",
31
- "axios": "1.4.0",
24
+ "@opentelemetry/instrumentation": "0.41.2",
25
+ "@opentelemetry/instrumentation-dns": "0.32.4",
26
+ "@opentelemetry/instrumentation-express": "0.33.3",
27
+ "@opentelemetry/instrumentation-http": "0.41.2",
28
+ "@opentelemetry/instrumentation-winston": "0.32.2",
29
+ "@opentelemetry/sdk-node": "0.41.2",
30
+ "@opentelemetry/sdk-trace-node": "1.15.2",
31
+ "axios": "1.5.1",
32
32
  "content-disposition-parser": "1.0.2",
33
- "date-and-time": "3.0.2",
34
- "winston": "3.8.2",
35
- "zod": "3.21.4"
33
+ "date-and-time": "3.0.3",
34
+ "lodash": "4.17.21",
35
+ "winston": "3.10.0",
36
+ "zod": "3.22.4"
36
37
  },
37
38
  "devDependencies": {
38
- "@types/jest": "29.5.3",
39
- "@types/node": "18.16.20",
40
- "@typescript-eslint/eslint-plugin": "5.59.11",
41
- "@typescript-eslint/parser": "5.59.11",
42
- "eslint": "8.40.0",
43
- "eslint-config-airbnb-typescript": "17.0.0",
44
- "eslint-config-prettier": "8.8.0",
45
- "eslint-plugin-import": "2.27.5",
39
+ "@types/jest": "29.5.10",
40
+ "@types/lodash": "4.14.202",
41
+ "@types/node": "18.17.19",
42
+ "@typescript-eslint/eslint-plugin": "5.62.0",
43
+ "@typescript-eslint/parser": "5.62.0",
44
+ "eslint": "8.48.0",
45
+ "eslint-config-airbnb-typescript": "17.1.0",
46
+ "eslint-config-prettier": "8.10.0",
47
+ "eslint-plugin-import": "2.28.1",
46
48
  "eslint-plugin-prettier": "4.2.1",
47
49
  "husky": "8.0.3",
48
- "jest": "29.5.0",
49
- "jest-mock-extended": "3.0.4",
50
+ "jest": "29.6.4",
51
+ "jest-mock-extended": "3.0.5",
50
52
  "jest-sonar-reporter": "2.0.0",
51
- "lint-staged": "13.2.3",
52
- "nock": "13.3.2",
53
+ "lint-staged": "13.3.0",
54
+ "nock": "13.3.8",
53
55
  "prettier": "2.8.8",
54
56
  "ts-jest": "29.1.1",
55
57
  "ts-node": "10.9.1",
56
- "typescript": "5.0.4"
58
+ "typescript": "5.2.2"
57
59
  },
58
60
  "prettier": {
59
61
  "printWidth": 100,