@moreapp/common-nodejs 0.4.0 → 0.5.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # MoreApp Common NodeJS
2
2
 
3
- .. TODO
3
+ A collection of shared NodeJS code.
4
4
 
5
5
  # Pre-commit hooks
6
6
 
@@ -0,0 +1,22 @@
1
+ /// <reference types="node" />
2
+ import { AxiosRequestConfig } from "axios";
3
+ interface Options {
4
+ serviceName: string;
5
+ prefix: string;
6
+ seal: string;
7
+ axios?: Omit<AxiosRequestConfig, "baseURL">;
8
+ }
9
+ export interface BinaryFile {
10
+ filename?: string;
11
+ contentType: string;
12
+ buffer: Buffer;
13
+ }
14
+ export default class MoreAppClient {
15
+ private readonly client;
16
+ constructor(options: Options);
17
+ getBinary(path: string): Promise<BinaryFile>;
18
+ get(path: string): Promise<any>;
19
+ post(path: string, payload: Record<string, any>): Promise<any>;
20
+ delete(path: string): Promise<any>;
21
+ }
22
+ export {};
@@ -0,0 +1,58 @@
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
+ const axios_1 = __importDefault(require("axios"));
7
+ class MoreAppClient {
8
+ constructor(options) {
9
+ this.client = axios_1.default.create({
10
+ ...options.axios,
11
+ baseURL: options.prefix,
12
+ headers: {
13
+ ...options.axios?.headers,
14
+ "X-More-Seal": options.seal,
15
+ "User-Agent": `MoreApp NodeJS Client (${options.serviceName}) (https://moreapp.com)`,
16
+ },
17
+ });
18
+ }
19
+ async getBinary(path) {
20
+ const response = await this.client.get(path, {
21
+ responseType: "arraybuffer",
22
+ });
23
+ return {
24
+ filename: getFilename(response),
25
+ contentType: response.headers["content-type"] || "unknown",
26
+ buffer: response.data,
27
+ };
28
+ }
29
+ async get(path) {
30
+ const response = await this.client.get(path, {
31
+ responseType: "json",
32
+ });
33
+ return response.data;
34
+ }
35
+ async post(path, payload) {
36
+ const response = await this.client.post(path, payload, {
37
+ responseType: "json",
38
+ });
39
+ return response.data;
40
+ }
41
+ async delete(path) {
42
+ const response = await this.client.delete(path, {
43
+ responseType: "json",
44
+ });
45
+ return response.data;
46
+ }
47
+ }
48
+ exports.default = MoreAppClient;
49
+ function getFilename(res) {
50
+ const contentDispositionHeader = res.headers["content-disposition"];
51
+ if (contentDispositionHeader) {
52
+ const execParts = /filename="(.*)"/gi.exec(contentDispositionHeader);
53
+ if (execParts && execParts.length > 1) {
54
+ return execParts[1];
55
+ }
56
+ }
57
+ return undefined;
58
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,46 @@
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
+ const MoreAppClient_1 = __importDefault(require("./MoreAppClient"));
7
+ const nock_1 = __importDefault(require("nock"));
8
+ const axios_1 = require("axios");
9
+ test("download binary file", async () => {
10
+ const file = Buffer.from("Some data");
11
+ const apiMock = (0, nock_1.default)("https://api.moreapp.com")
12
+ .get("/download")
13
+ .matchHeader("x-more-seal", "my-seal")
14
+ .reply(200, file, {
15
+ "Content-Type": "image/jpg",
16
+ "content-disposition": 'filename="my-photo.jpg"',
17
+ });
18
+ const client = new MoreAppClient_1.default({
19
+ serviceName: "Common Test",
20
+ prefix: "https://api.moreapp.com",
21
+ seal: "my-seal",
22
+ });
23
+ const binaryFile = await client.getBinary("/download");
24
+ expect(binaryFile.buffer).toStrictEqual(file);
25
+ expect(binaryFile.contentType).toBe("image/jpg");
26
+ expect(binaryFile.filename).toBe("my-photo.jpg");
27
+ apiMock.done();
28
+ });
29
+ test("404", async () => {
30
+ const apiMock = (0, nock_1.default)("https://api.moreapp.com").get("/download").reply(404);
31
+ const client = new MoreAppClient_1.default({
32
+ serviceName: "Common Test",
33
+ prefix: "https://api.moreapp.com",
34
+ seal: "my-seal",
35
+ });
36
+ await expect(client.getBinary("/download")).rejects.toStrictEqual(new axios_1.AxiosError("Request failed with status code 404"));
37
+ apiMock.done();
38
+ });
39
+ test("unable to connect", async () => {
40
+ const client = new MoreAppClient_1.default({
41
+ serviceName: "Common Test",
42
+ prefix: "https://non-existing.moreapp.com",
43
+ seal: "my-seal",
44
+ });
45
+ await expect(client.getBinary("/download")).rejects.toThrowError("getaddrinfo ENOTFOUND non-existing.moreapp.com");
46
+ });
@@ -0,0 +1,4 @@
1
+ export declare function isDate(string: string): boolean;
2
+ export declare function isDateTime(string: string): boolean;
3
+ export declare function formatDate(dateString: string, format: string): string;
4
+ export declare function formatDateTime(dateTime: string | number, format: string): string;
@@ -0,0 +1,41 @@
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.formatDateTime = exports.formatDate = exports.isDateTime = exports.isDate = void 0;
7
+ const date_and_time_1 = __importDefault(require("date-and-time"));
8
+ const DATE_REGEX = /^\d{4}-\d{1,2}-\d{1,2}$/;
9
+ const DATE_TIME_REGEX = /^\d{4}-\d{1,2}-\d{1,2} \d{1,2}:\d{2}$/;
10
+ function isDate(string) {
11
+ return DATE_REGEX.test(string) && !isNaN(Date.parse(string));
12
+ }
13
+ exports.isDate = isDate;
14
+ function isDateTime(string) {
15
+ return DATE_TIME_REGEX.test(string) && !isNaN(Date.parse(string));
16
+ }
17
+ exports.isDateTime = isDateTime;
18
+ function formatDate(dateString, format) {
19
+ const date = date_and_time_1.default.parse(dateString, "YYYY-MM-DD");
20
+ return date_and_time_1.default.format(date, formatDateFormat(format));
21
+ }
22
+ exports.formatDate = formatDate;
23
+ function formatDateTime(dateTime, format) {
24
+ const date = typeof dateTime === "string"
25
+ ? date_and_time_1.default.parse(dateTime, "YYYY-MM-DD HH:mm", true)
26
+ : new Date(dateTime);
27
+ return date_and_time_1.default.format(date, formatDateFormat(format) + " HH:mm", true);
28
+ }
29
+ exports.formatDateTime = formatDateTime;
30
+ function formatDateFormat(format) {
31
+ switch (format) {
32
+ case "DDMMYYYY":
33
+ return "DD-MM-YYYY";
34
+ case "MMDDYYYY":
35
+ return "MM-DD-YYYY";
36
+ case "YYYYMMDD":
37
+ return "YYYY-MM-DD";
38
+ default:
39
+ return "DD-MM-YYYY";
40
+ }
41
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const dateUtil_1 = require("./dateUtil");
4
+ describe("isDate", () => {
5
+ test("should handle valid dates", async () => {
6
+ expect((0, dateUtil_1.isDate)("2020-01-01")).toBe(true);
7
+ expect((0, dateUtil_1.isDate)("2020-1-1")).toBe(true);
8
+ expect((0, dateUtil_1.isDate)("0000-1-1")).toBe(true);
9
+ });
10
+ test("should handle invalid dates", async () => {
11
+ expect((0, dateUtil_1.isDate)("not-a-date")).toBe(false);
12
+ expect((0, dateUtil_1.isDate)("3039-20-01")).toBe(false);
13
+ });
14
+ });
15
+ describe("isDateTime", () => {
16
+ test("should handle valid date times", async () => {
17
+ expect((0, dateUtil_1.isDateTime)("2020-01-01 12:00")).toBe(true);
18
+ expect((0, dateUtil_1.isDateTime)("2020-01-01 0:00")).toBe(true);
19
+ });
20
+ test("should handle invalid date times", async () => {
21
+ expect((0, dateUtil_1.isDateTime)("2020-01-01 0:99")).toBe(false);
22
+ expect((0, dateUtil_1.isDateTime)("2020-01-01 25:12")).toBe(false);
23
+ });
24
+ });
25
+ describe("formatDate", () => {
26
+ test("should format to given input", () => {
27
+ expect((0, dateUtil_1.formatDate)("2022-02-18", "DDMMYYYY")).toBe("18-02-2022");
28
+ expect((0, dateUtil_1.formatDate)("2022-02-18", "MMDDYYYY")).toBe("02-18-2022");
29
+ expect((0, dateUtil_1.formatDate)("2022-02-18", "YYYYMMDD")).toBe("2022-02-18");
30
+ expect((0, dateUtil_1.formatDate)("2022-02-18", "invalid")).toBe("18-02-2022");
31
+ });
32
+ });
33
+ describe("formatDateTime", () => {
34
+ test("should format to given input", () => {
35
+ expect((0, dateUtil_1.formatDateTime)(1645191420000, "DDMMYYYY")).toBe("18-02-2022 13:37");
36
+ expect((0, dateUtil_1.formatDateTime)("2022-02-18 13:37", "DDMMYYYY")).toBe("18-02-2022 13:37");
37
+ expect((0, dateUtil_1.formatDateTime)("2022-02-18 13:37", "MMDDYYYY")).toBe("02-18-2022 13:37");
38
+ expect((0, dateUtil_1.formatDateTime)("2022-02-18 13:37", "YYYYMMDD")).toBe("2022-02-18 13:37");
39
+ expect((0, dateUtil_1.formatDateTime)("2022-02-18 13:37", "invalid")).toBe("18-02-2022 13:37");
40
+ });
41
+ });
package/dist/index.d.ts CHANGED
@@ -1,3 +1,9 @@
1
+ import MoreAppClient from "./MoreAppClient";
2
+ export * from "./types";
3
+ export * from "./schema";
1
4
  export * from "./tracer";
2
5
  export * from "./logger";
6
+ export * from "./dateUtil";
3
7
  export * from "./utils";
8
+ export { BinaryFile } from "./MoreAppClient";
9
+ export { MoreAppClient };
package/dist/index.js CHANGED
@@ -13,7 +13,16 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
13
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
16
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.MoreAppClient = void 0;
21
+ const MoreAppClient_1 = __importDefault(require("./MoreAppClient"));
22
+ exports.MoreAppClient = MoreAppClient_1.default;
23
+ __exportStar(require("./types"), exports);
24
+ __exportStar(require("./schema"), exports);
17
25
  __exportStar(require("./tracer"), exports);
18
26
  __exportStar(require("./logger"), exports);
27
+ __exportStar(require("./dateUtil"), exports);
19
28
  __exportStar(require("./utils"), exports);
@@ -0,0 +1,400 @@
1
+ import { z } from "zod";
2
+ export declare const FormVersionFieldSchema: z.ZodObject<{
3
+ uid: z.ZodString;
4
+ properties: z.ZodObject<{
5
+ data_name: z.ZodOptional<z.ZodString>;
6
+ }, "strip", z.ZodTypeAny, {
7
+ data_name?: string | undefined;
8
+ }, {
9
+ data_name?: string | undefined;
10
+ }>;
11
+ }, "strip", z.ZodTypeAny, {
12
+ uid: string;
13
+ properties: {
14
+ data_name?: string | undefined;
15
+ };
16
+ }, {
17
+ uid: string;
18
+ properties: {
19
+ data_name?: string | undefined;
20
+ };
21
+ }>;
22
+ export declare const FormVersionSchema: z.ZodObject<{
23
+ fields: z.ZodArray<z.ZodObject<{
24
+ uid: z.ZodString;
25
+ properties: z.ZodObject<{
26
+ data_name: z.ZodOptional<z.ZodString>;
27
+ }, "strip", z.ZodTypeAny, {
28
+ data_name?: string | undefined;
29
+ }, {
30
+ data_name?: string | undefined;
31
+ }>;
32
+ }, "strip", z.ZodTypeAny, {
33
+ uid: string;
34
+ properties: {
35
+ data_name?: string | undefined;
36
+ };
37
+ }, {
38
+ uid: string;
39
+ properties: {
40
+ data_name?: string | undefined;
41
+ };
42
+ }>, "many">;
43
+ }, "strip", z.ZodTypeAny, {
44
+ fields: {
45
+ uid: string;
46
+ properties: {
47
+ data_name?: string | undefined;
48
+ };
49
+ }[];
50
+ }, {
51
+ fields: {
52
+ uid: string;
53
+ properties: {
54
+ data_name?: string | undefined;
55
+ };
56
+ }[];
57
+ }>;
58
+ export declare const SubmissionSchema: z.ZodObject<{
59
+ id: z.ZodString;
60
+ info: z.ZodObject<{
61
+ customerId: z.ZodNumber;
62
+ formName: z.ZodString;
63
+ date: z.ZodNumber;
64
+ userId: z.ZodString;
65
+ }, "strip", z.ZodTypeAny, {
66
+ date: number;
67
+ customerId: number;
68
+ formName: string;
69
+ userId: string;
70
+ }, {
71
+ date: number;
72
+ customerId: number;
73
+ formName: string;
74
+ userId: string;
75
+ }>;
76
+ meta: z.ZodObject<{
77
+ registrationDate: z.ZodString;
78
+ instructionId: z.ZodNullable<z.ZodString>;
79
+ serialNumber: z.ZodNumber;
80
+ guid: z.ZodString;
81
+ location: z.ZodNullable<z.ZodObject<{
82
+ longitude: z.ZodString;
83
+ latitude: z.ZodString;
84
+ }, "strip", z.ZodTypeAny, {
85
+ longitude: string;
86
+ latitude: string;
87
+ }, {
88
+ longitude: string;
89
+ latitude: string;
90
+ }>>;
91
+ }, "strip", z.ZodTypeAny, {
92
+ registrationDate: string;
93
+ instructionId: string | null;
94
+ serialNumber: number;
95
+ guid: string;
96
+ location: {
97
+ longitude: string;
98
+ latitude: string;
99
+ } | null;
100
+ }, {
101
+ registrationDate: string;
102
+ instructionId: string | null;
103
+ serialNumber: number;
104
+ guid: string;
105
+ location: {
106
+ longitude: string;
107
+ latitude: string;
108
+ } | null;
109
+ }>;
110
+ data: z.ZodRecord<z.ZodString, z.ZodAny>;
111
+ mailStatuses: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
112
+ pdfFileId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
113
+ emailAddresses: z.ZodArray<z.ZodString, "many">;
114
+ }, "strip", z.ZodTypeAny, {
115
+ emailAddresses: string[];
116
+ pdfFileId?: string | null | undefined;
117
+ }, {
118
+ emailAddresses: string[];
119
+ pdfFileId?: string | null | undefined;
120
+ }>, "many">>>;
121
+ }, "strip", z.ZodTypeAny, {
122
+ data: Record<string, any>;
123
+ id: string;
124
+ info: {
125
+ date: number;
126
+ customerId: number;
127
+ formName: string;
128
+ userId: string;
129
+ };
130
+ meta: {
131
+ registrationDate: string;
132
+ instructionId: string | null;
133
+ serialNumber: number;
134
+ guid: string;
135
+ location: {
136
+ longitude: string;
137
+ latitude: string;
138
+ } | null;
139
+ };
140
+ mailStatuses?: {
141
+ emailAddresses: string[];
142
+ pdfFileId?: string | null | undefined;
143
+ }[] | null | undefined;
144
+ }, {
145
+ data: Record<string, any>;
146
+ id: string;
147
+ info: {
148
+ date: number;
149
+ customerId: number;
150
+ formName: string;
151
+ userId: string;
152
+ };
153
+ meta: {
154
+ registrationDate: string;
155
+ instructionId: string | null;
156
+ serialNumber: number;
157
+ guid: string;
158
+ location: {
159
+ longitude: string;
160
+ latitude: string;
161
+ } | null;
162
+ };
163
+ mailStatuses?: {
164
+ emailAddresses: string[];
165
+ pdfFileId?: string | null | undefined;
166
+ }[] | null | undefined;
167
+ }>;
168
+ export declare const BaseIntegrationRequestSchema: z.ZodObject<{
169
+ view: z.ZodObject<{
170
+ fields: z.ZodArray<z.ZodObject<{
171
+ uid: z.ZodString;
172
+ properties: z.ZodObject<{
173
+ data_name: z.ZodOptional<z.ZodString>;
174
+ }, "strip", z.ZodTypeAny, {
175
+ data_name?: string | undefined;
176
+ }, {
177
+ data_name?: string | undefined;
178
+ }>;
179
+ }, "strip", z.ZodTypeAny, {
180
+ uid: string;
181
+ properties: {
182
+ data_name?: string | undefined;
183
+ };
184
+ }, {
185
+ uid: string;
186
+ properties: {
187
+ data_name?: string | undefined;
188
+ };
189
+ }>, "many">;
190
+ }, "strip", z.ZodTypeAny, {
191
+ fields: {
192
+ uid: string;
193
+ properties: {
194
+ data_name?: string | undefined;
195
+ };
196
+ }[];
197
+ }, {
198
+ fields: {
199
+ uid: string;
200
+ properties: {
201
+ data_name?: string | undefined;
202
+ };
203
+ }[];
204
+ }>;
205
+ registration: z.ZodObject<{
206
+ id: z.ZodString;
207
+ info: z.ZodObject<{
208
+ customerId: z.ZodNumber;
209
+ formName: z.ZodString;
210
+ date: z.ZodNumber;
211
+ userId: z.ZodString;
212
+ }, "strip", z.ZodTypeAny, {
213
+ date: number;
214
+ customerId: number;
215
+ formName: string;
216
+ userId: string;
217
+ }, {
218
+ date: number;
219
+ customerId: number;
220
+ formName: string;
221
+ userId: string;
222
+ }>;
223
+ meta: z.ZodObject<{
224
+ registrationDate: z.ZodString;
225
+ instructionId: z.ZodNullable<z.ZodString>;
226
+ serialNumber: z.ZodNumber;
227
+ guid: z.ZodString;
228
+ location: z.ZodNullable<z.ZodObject<{
229
+ longitude: z.ZodString;
230
+ latitude: z.ZodString;
231
+ }, "strip", z.ZodTypeAny, {
232
+ longitude: string;
233
+ latitude: string;
234
+ }, {
235
+ longitude: string;
236
+ latitude: string;
237
+ }>>;
238
+ }, "strip", z.ZodTypeAny, {
239
+ registrationDate: string;
240
+ instructionId: string | null;
241
+ serialNumber: number;
242
+ guid: string;
243
+ location: {
244
+ longitude: string;
245
+ latitude: string;
246
+ } | null;
247
+ }, {
248
+ registrationDate: string;
249
+ instructionId: string | null;
250
+ serialNumber: number;
251
+ guid: string;
252
+ location: {
253
+ longitude: string;
254
+ latitude: string;
255
+ } | null;
256
+ }>;
257
+ data: z.ZodRecord<z.ZodString, z.ZodAny>;
258
+ mailStatuses: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
259
+ pdfFileId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
260
+ emailAddresses: z.ZodArray<z.ZodString, "many">;
261
+ }, "strip", z.ZodTypeAny, {
262
+ emailAddresses: string[];
263
+ pdfFileId?: string | null | undefined;
264
+ }, {
265
+ emailAddresses: string[];
266
+ pdfFileId?: string | null | undefined;
267
+ }>, "many">>>;
268
+ }, "strip", z.ZodTypeAny, {
269
+ data: Record<string, any>;
270
+ id: string;
271
+ info: {
272
+ date: number;
273
+ customerId: number;
274
+ formName: string;
275
+ userId: string;
276
+ };
277
+ meta: {
278
+ registrationDate: string;
279
+ instructionId: string | null;
280
+ serialNumber: number;
281
+ guid: string;
282
+ location: {
283
+ longitude: string;
284
+ latitude: string;
285
+ } | null;
286
+ };
287
+ mailStatuses?: {
288
+ emailAddresses: string[];
289
+ pdfFileId?: string | null | undefined;
290
+ }[] | null | undefined;
291
+ }, {
292
+ data: Record<string, any>;
293
+ id: string;
294
+ info: {
295
+ date: number;
296
+ customerId: number;
297
+ formName: string;
298
+ userId: string;
299
+ };
300
+ meta: {
301
+ registrationDate: string;
302
+ instructionId: string | null;
303
+ serialNumber: number;
304
+ guid: string;
305
+ location: {
306
+ longitude: string;
307
+ latitude: string;
308
+ } | null;
309
+ };
310
+ mailStatuses?: {
311
+ emailAddresses: string[];
312
+ pdfFileId?: string | null | undefined;
313
+ }[] | null | undefined;
314
+ }>;
315
+ seal: z.ZodString;
316
+ origin: z.ZodString;
317
+ settings: z.ZodObject<{
318
+ dateFormat: z.ZodString;
319
+ }, "strip", z.ZodTypeAny, {
320
+ dateFormat: string;
321
+ }, {
322
+ dateFormat: string;
323
+ }>;
324
+ }, "strip", z.ZodTypeAny, {
325
+ view: {
326
+ fields: {
327
+ uid: string;
328
+ properties: {
329
+ data_name?: string | undefined;
330
+ };
331
+ }[];
332
+ };
333
+ registration: {
334
+ data: Record<string, any>;
335
+ id: string;
336
+ info: {
337
+ date: number;
338
+ customerId: number;
339
+ formName: string;
340
+ userId: string;
341
+ };
342
+ meta: {
343
+ registrationDate: string;
344
+ instructionId: string | null;
345
+ serialNumber: number;
346
+ guid: string;
347
+ location: {
348
+ longitude: string;
349
+ latitude: string;
350
+ } | null;
351
+ };
352
+ mailStatuses?: {
353
+ emailAddresses: string[];
354
+ pdfFileId?: string | null | undefined;
355
+ }[] | null | undefined;
356
+ };
357
+ seal: string;
358
+ origin: string;
359
+ settings: {
360
+ dateFormat: string;
361
+ };
362
+ }, {
363
+ view: {
364
+ fields: {
365
+ uid: string;
366
+ properties: {
367
+ data_name?: string | undefined;
368
+ };
369
+ }[];
370
+ };
371
+ registration: {
372
+ data: Record<string, any>;
373
+ id: string;
374
+ info: {
375
+ date: number;
376
+ customerId: number;
377
+ formName: string;
378
+ userId: string;
379
+ };
380
+ meta: {
381
+ registrationDate: string;
382
+ instructionId: string | null;
383
+ serialNumber: number;
384
+ guid: string;
385
+ location: {
386
+ longitude: string;
387
+ latitude: string;
388
+ } | null;
389
+ };
390
+ mailStatuses?: {
391
+ emailAddresses: string[];
392
+ pdfFileId?: string | null | undefined;
393
+ }[] | null | undefined;
394
+ };
395
+ seal: string;
396
+ origin: string;
397
+ settings: {
398
+ dateFormat: string;
399
+ };
400
+ }>;
package/dist/schema.js ADDED
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseIntegrationRequestSchema = exports.SubmissionSchema = exports.FormVersionSchema = exports.FormVersionFieldSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.FormVersionFieldSchema = zod_1.z.object({
6
+ uid: zod_1.z.string(),
7
+ properties: zod_1.z.object({
8
+ data_name: zod_1.z.string().optional(),
9
+ }),
10
+ });
11
+ exports.FormVersionSchema = zod_1.z.object({
12
+ fields: zod_1.z.array(exports.FormVersionFieldSchema),
13
+ });
14
+ exports.SubmissionSchema = zod_1.z.object({
15
+ id: zod_1.z.string(),
16
+ info: zod_1.z.object({
17
+ customerId: zod_1.z.number(),
18
+ formName: zod_1.z.string(),
19
+ date: zod_1.z.number(),
20
+ userId: zod_1.z.string(),
21
+ }),
22
+ meta: zod_1.z.object({
23
+ registrationDate: zod_1.z.string(),
24
+ instructionId: zod_1.z.string().nullable(),
25
+ serialNumber: zod_1.z.number(),
26
+ guid: zod_1.z.string(),
27
+ location: zod_1.z
28
+ .object({
29
+ longitude: zod_1.z.string(),
30
+ latitude: zod_1.z.string(),
31
+ })
32
+ .nullable(),
33
+ }),
34
+ data: zod_1.z.record(zod_1.z.any()),
35
+ mailStatuses: zod_1.z
36
+ .array(zod_1.z.object({
37
+ pdfFileId: zod_1.z.string().nullish(),
38
+ emailAddresses: zod_1.z.array(zod_1.z.string().email()),
39
+ }))
40
+ .nullish(),
41
+ });
42
+ exports.BaseIntegrationRequestSchema = zod_1.z.object({
43
+ view: exports.FormVersionSchema,
44
+ registration: exports.SubmissionSchema,
45
+ seal: zod_1.z.string(),
46
+ origin: zod_1.z.string(),
47
+ settings: zod_1.z.object({
48
+ dateFormat: zod_1.z.string(),
49
+ }),
50
+ });
package/dist/tracer.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  import * as types from "@opentelemetry/instrumentation/build/src/types";
2
- export declare const tracer: (serviceName: string, instrumentations: types.Instrumentation[]) => void;
2
+ export declare const tracer: (serviceName: string, extraInstrumentations: types.Instrumentation[]) => void;
package/dist/tracer.js CHANGED
@@ -13,7 +13,7 @@ const resources_1 = require("@opentelemetry/resources");
13
13
  const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
14
14
  const propagator_b3_1 = require("@opentelemetry/propagator-b3");
15
15
  const utils_1 = require("./utils");
16
- const tracer = (serviceName, instrumentations) => {
16
+ const tracer = (serviceName, extraInstrumentations) => {
17
17
  const provider = new sdk_trace_node_1.NodeTracerProvider({
18
18
  resource: new resources_1.Resource({
19
19
  [semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME]: serviceName,
@@ -36,7 +36,7 @@ const tracer = (serviceName, instrumentations) => {
36
36
  }),
37
37
  new instrumentation_express_1.ExpressInstrumentation(),
38
38
  new instrumentation_winston_1.WinstonInstrumentation(),
39
- ...instrumentations,
39
+ ...extraInstrumentations,
40
40
  ],
41
41
  });
42
42
  if (process.env["STACKDRIVER_TRACING_ENABLED"] === "true") {
@@ -0,0 +1,22 @@
1
+ import { z } from "zod";
2
+ import { FormVersionFieldSchema, SubmissionSchema } from "./schema";
3
+ export declare type Submission = z.infer<typeof SubmissionSchema>;
4
+ export declare type FormVersionField = z.infer<typeof FormVersionFieldSchema>;
5
+ export declare type IntegrationTestResponse = {
6
+ status: "VALID" | "SUCCESS";
7
+ } | {
8
+ status: "INVALID";
9
+ globalError: string;
10
+ fieldErrors?: Record<string, any>;
11
+ };
12
+ export declare type IntegrationHandleResponse = {
13
+ status: "VALID" | "SUCCESS";
14
+ files?: {
15
+ type: string;
16
+ name: string;
17
+ data: string;
18
+ }[];
19
+ } | {
20
+ status: "INVALID";
21
+ message: string;
22
+ };
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moreapp/common-nodejs",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "license": "UNLICENSED",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -28,7 +28,10 @@
28
28
  "@opentelemetry/instrumentation-winston": "0.31.1",
29
29
  "@opentelemetry/sdk-node": "0.36.1",
30
30
  "@opentelemetry/sdk-trace-node": "1.10.1",
31
- "winston": "3.8.2"
31
+ "axios": "1.3.4",
32
+ "date-and-time": "2.4.3",
33
+ "winston": "3.8.2",
34
+ "zod": "3.21.4"
32
35
  },
33
36
  "devDependencies": {
34
37
  "@types/jest": "29.2.0",
@@ -45,6 +48,7 @@
45
48
  "jest-mock-extended": "3.0.1",
46
49
  "jest-sonar-reporter": "2.0.0",
47
50
  "lint-staged": "13.0.3",
51
+ "nock": "13.3.0",
48
52
  "prettier": "2.7.1",
49
53
  "ts-jest": "29.0.3",
50
54
  "ts-node": "10.9.1",