@moreapp/common-nodejs 0.6.0 → 0.7.1
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/MoreAppClient.d.ts +2 -2
- package/dist/MoreAppClient.js +2 -7
- package/dist/MoreAppClient.test.js +34 -1
- package/dist/types.d.ts +4 -3
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +6 -1
- package/dist/utils.test.js +10 -0
- package/package.json +2 -1
package/dist/MoreAppClient.d.ts
CHANGED
|
@@ -15,8 +15,8 @@ export default class MoreAppClient {
|
|
|
15
15
|
private readonly client;
|
|
16
16
|
constructor(options: Options);
|
|
17
17
|
getBinary(path: string): Promise<BinaryFile>;
|
|
18
|
-
get(path: string): Promise<
|
|
19
|
-
post(path: string, payload: Record<string, any>): Promise<
|
|
18
|
+
get<T>(path: string): Promise<T>;
|
|
19
|
+
post<T>(path: string, payload: Record<string, any>): Promise<T>;
|
|
20
20
|
delete(path: string): Promise<any>;
|
|
21
21
|
}
|
|
22
22
|
export {};
|
package/dist/MoreAppClient.js
CHANGED
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const axios_1 = __importDefault(require("axios"));
|
|
7
|
+
const content_disposition_parser_1 = __importDefault(require("content-disposition-parser"));
|
|
7
8
|
class MoreAppClient {
|
|
8
9
|
constructor(options) {
|
|
9
10
|
this.client = axios_1.default.create({
|
|
@@ -48,11 +49,5 @@ class MoreAppClient {
|
|
|
48
49
|
exports.default = MoreAppClient;
|
|
49
50
|
function getFilename(res) {
|
|
50
51
|
const contentDispositionHeader = res.headers["content-disposition"];
|
|
51
|
-
|
|
52
|
-
const execParts = /filename="(.*)"/gi.exec(contentDispositionHeader);
|
|
53
|
-
if (execParts && execParts.length > 1) {
|
|
54
|
-
return execParts[1];
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return undefined;
|
|
52
|
+
return (0, content_disposition_parser_1.default)(contentDispositionHeader)?.filename;
|
|
58
53
|
}
|
|
@@ -13,7 +13,7 @@ test("download binary file", async () => {
|
|
|
13
13
|
.matchHeader("x-more-seal", "my-seal")
|
|
14
14
|
.reply(200, file, {
|
|
15
15
|
"Content-Type": "image/jpg",
|
|
16
|
-
"content-disposition": 'filename="my-photo.jpg"',
|
|
16
|
+
"content-disposition": 'attachment; filename="my-photo.jpg"',
|
|
17
17
|
});
|
|
18
18
|
const client = new MoreAppClient_1.default({
|
|
19
19
|
serviceName: "Common Test",
|
|
@@ -44,3 +44,36 @@ test("unable to connect", async () => {
|
|
|
44
44
|
});
|
|
45
45
|
await expect(client.getBinary("/download")).rejects.toThrowError("getaddrinfo ENOTFOUND non-existing.moreapp.com");
|
|
46
46
|
});
|
|
47
|
+
const client = new MoreAppClient_1.default({
|
|
48
|
+
serviceName: "Common Test",
|
|
49
|
+
prefix: "https://api.moreapp.com",
|
|
50
|
+
seal: "my-seal",
|
|
51
|
+
});
|
|
52
|
+
test("Handle non existing file", async () => {
|
|
53
|
+
const apiMock = (0, nock_1.default)("https://api.moreapp.com").get("/download").reply(404);
|
|
54
|
+
await expect(client.getBinary("/download")).rejects.toThrow("Request failed with status code 404");
|
|
55
|
+
apiMock.done();
|
|
56
|
+
});
|
|
57
|
+
test("Handle missing 'content-type' header", async () => {
|
|
58
|
+
const apiMock = (0, nock_1.default)("https://api.moreapp.com").get("/download").reply(200);
|
|
59
|
+
const binaryFile = await client.getBinary("/download");
|
|
60
|
+
expect(binaryFile).not.toBeNull();
|
|
61
|
+
expect(binaryFile.contentType).toBe("unknown");
|
|
62
|
+
apiMock.done();
|
|
63
|
+
});
|
|
64
|
+
test("Handle missing 'content-disposition' header", async () => {
|
|
65
|
+
const apiMock = (0, nock_1.default)("https://api.moreapp.com").get("/download").reply(200);
|
|
66
|
+
const binaryFile = await client.getBinary("/download");
|
|
67
|
+
expect(binaryFile).not.toBeNull();
|
|
68
|
+
expect(binaryFile.filename).toBeUndefined();
|
|
69
|
+
apiMock.done();
|
|
70
|
+
});
|
|
71
|
+
test("Handle invalid 'content-disposition' header", async () => {
|
|
72
|
+
const apiMock = (0, nock_1.default)("https://api.moreapp.com").get("/download").reply(200, {}, {
|
|
73
|
+
"content-disposition": "filename=my-photo.png",
|
|
74
|
+
});
|
|
75
|
+
const binaryFile = await client.getBinary("/download");
|
|
76
|
+
expect(binaryFile).not.toBeNull();
|
|
77
|
+
expect(binaryFile.filename).toBeUndefined();
|
|
78
|
+
apiMock.done();
|
|
79
|
+
});
|
package/dist/types.d.ts
CHANGED
|
@@ -3,20 +3,21 @@ import { FormVersionFieldSchema, SubmissionSchema } from "./schema";
|
|
|
3
3
|
export declare type Submission = z.infer<typeof SubmissionSchema>;
|
|
4
4
|
export declare type FormVersionField = z.infer<typeof FormVersionFieldSchema>;
|
|
5
5
|
export declare type IntegrationTestResponse = {
|
|
6
|
-
status: "VALID"
|
|
6
|
+
status: "VALID";
|
|
7
7
|
} | {
|
|
8
8
|
status: "INVALID";
|
|
9
9
|
globalError: string;
|
|
10
10
|
fieldErrors?: Record<string, any>;
|
|
11
11
|
};
|
|
12
12
|
export declare type IntegrationHandleResponse = {
|
|
13
|
-
status: "
|
|
13
|
+
status: "SUCCESS";
|
|
14
14
|
files?: {
|
|
15
15
|
type: string;
|
|
16
16
|
name: string;
|
|
17
17
|
data: string;
|
|
18
18
|
}[];
|
|
19
|
+
data?: Record<string, any>;
|
|
19
20
|
} | {
|
|
20
|
-
status: "
|
|
21
|
+
status: "ERROR";
|
|
21
22
|
message: string;
|
|
22
23
|
};
|
package/dist/utils.d.ts
CHANGED
package/dist/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.currentTraceId = exports.environmentVariable = void 0;
|
|
3
|
+
exports.isValidEmail = exports.currentTraceId = exports.environmentVariable = void 0;
|
|
4
4
|
const context_utils_1 = require("@opentelemetry/api/build/src/trace/context-utils");
|
|
5
5
|
const api_1 = require("@opentelemetry/api");
|
|
6
6
|
function environmentVariable(key, fallback) {
|
|
@@ -15,3 +15,8 @@ function currentTraceId() {
|
|
|
15
15
|
return (0, context_utils_1.getSpanContext)(api_1.context.active())?.traceId;
|
|
16
16
|
}
|
|
17
17
|
exports.currentTraceId = currentTraceId;
|
|
18
|
+
const validEmailPattern = /^[A-Z0-9._&%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i;
|
|
19
|
+
function isValidEmail(email) {
|
|
20
|
+
return validEmailPattern.test(email);
|
|
21
|
+
}
|
|
22
|
+
exports.isValidEmail = isValidEmail;
|
package/dist/utils.test.js
CHANGED
|
@@ -13,3 +13,13 @@ describe("environmentVariable", () => {
|
|
|
13
13
|
expect(() => (0, utils_1.environmentVariable)("COMMONS_NODEJS_TEST_NON_EXISTING")).toThrow("Missing environment variable 'COMMONS_NODEJS_TEST_NON_EXISTING'");
|
|
14
14
|
});
|
|
15
15
|
});
|
|
16
|
+
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);
|
|
20
|
+
});
|
|
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);
|
|
24
|
+
});
|
|
25
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moreapp/common-nodejs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"@opentelemetry/sdk-node": "0.36.1",
|
|
30
30
|
"@opentelemetry/sdk-trace-node": "1.10.1",
|
|
31
31
|
"axios": "1.3.4",
|
|
32
|
+
"content-disposition-parser": "1.0.2",
|
|
32
33
|
"date-and-time": "2.4.3",
|
|
33
34
|
"winston": "3.8.2",
|
|
34
35
|
"zod": "3.21.4"
|