@moreapp/common-nodejs 0.7.2 → 0.7.4

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,21 +1,47 @@
1
- # MoreApp Common NodeJS
1
+ # MoreApp Common Node.js
2
2
 
3
- A collection of shared NodeJS code.
3
+ This project contains common code that can be used for our Node.js projects.
4
4
 
5
- # Pre-commit hooks
5
+ ## Getting started
6
6
 
7
7
  Run `yarn prepare` once to install Git hooks, doing lints and prettier formatting
8
8
 
9
- ## Usage
9
+ ## Project usage
10
+
11
+ Most code can be used as is, except for tracing, see below.
10
12
 
11
13
  ### Tracing
12
14
 
13
- Tracing code should always be loaded first, before any other libraries. This is because the OpenTelemetry
14
- instrumentations monkey patch libraries to add tracing. This will break if the library has been loaded (import/require),
15
- because the unpatched library will be cached.
15
+ Tracing code should always be loaded (`import`/`require`) first, before any other libraries. This is because the
16
+ OpenTelemetry instrumentations monkey patch libraries to add tracing. Patching has to happen first, because already
17
+ loaded libraries will be cached by the module system.
16
18
 
17
- Put the following snippet on the first line of the entrypoint file.
19
+ The recommended way to do this, is to create a file `instrumentation.ts` with the following content (the extra
20
+ instrumentation is there as an example):
18
21
 
19
22
  ```
20
- require("@moreapp/common-nodejs/dist/tracer").tracer(<service_name>, {});
23
+ import { tracer } from "@moreapp/common-nodejs";
24
+ import { MongoDBInstrumentation } from "@opentelemetry/instrumentation-mongodb";
25
+
26
+ tracer("<SERVICE_NAME>", {
27
+ extraInstrumentations: [new MongoDBInstrumentation()],
28
+ });
21
29
  ```
30
+
31
+ And then use the `--require` [Node.js CLI option](https://nodejs.org/api/cli.html#-r---require-module) to load this file.
32
+
33
+ ## Creating a new release
34
+
35
+ Follow the steps below to create a new release:
36
+
37
+ 1. Ensure that the `master` branch has the commits you want to release
38
+ 2. Start a new build in Bitbucket Pipelines for the `master` branch with the `create-release` pipeline
39
+ 3. Select which type of version bump you want to do
40
+ 4. The build will automatically create a new version and publish it to NPM
41
+
42
+ ### Creating a local release
43
+
44
+ If you want to test new code in other projects, then you can link this repository using `Yarn`.
45
+
46
+ 1. Run `yarn link` in this repository
47
+ 2. Run `yarn link @moreapp/common-nodejs` in the project you want to use this repository in
@@ -49,5 +49,6 @@ class MoreAppClient {
49
49
  exports.default = MoreAppClient;
50
50
  function getFilename(res) {
51
51
  const contentDispositionHeader = res.headers["content-disposition"];
52
- return (0, content_disposition_parser_1.default)(contentDispositionHeader)?.filename;
52
+ const filename = (0, content_disposition_parser_1.default)(contentDispositionHeader)?.filename;
53
+ return filename ? decodeURI(filename) : undefined;
53
54
  }
@@ -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": 'attachment; filename="my-photo.jpg"',
16
+ "content-disposition": 'attachment; filename="my%20photo.jpg"',
17
17
  });
18
18
  const client = new MoreAppClient_1.default({
19
19
  serviceName: "Common Test",
@@ -23,7 +23,7 @@ test("download binary file", async () => {
23
23
  const binaryFile = await client.getBinary("/download");
24
24
  expect(binaryFile.buffer).toStrictEqual(file);
25
25
  expect(binaryFile.contentType).toBe("image/jpg");
26
- expect(binaryFile.filename).toBe("my-photo.jpg");
26
+ expect(binaryFile.filename).toBe("my photo.jpg");
27
27
  apiMock.done();
28
28
  });
29
29
  test("404", async () => {
package/dist/tracer.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import * as types from "@opentelemetry/instrumentation/build/src/types";
2
2
  export declare const tracer: (serviceName: string, { http, extraInstrumentations, debug, }: {
3
- http: {
3
+ http?: {
4
4
  portsToInstrument: number[];
5
- };
6
- extraInstrumentations: types.Instrumentation[];
7
- debug: boolean;
5
+ } | undefined;
6
+ extraInstrumentations?: types.Instrumentation[] | undefined;
7
+ debug?: boolean | undefined;
8
8
  }) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moreapp/common-nodejs",
3
- "version": "0.7.2",
3
+ "version": "0.7.4",
4
4
  "license": "UNLICENSED",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -22,24 +22,24 @@
22
22
  "@google-cloud/opentelemetry-cloud-trace-exporter": "2.0.0",
23
23
  "@opentelemetry/api": "1.4.1",
24
24
  "@opentelemetry/instrumentation": "0.38.0",
25
- "@opentelemetry/instrumentation-dns": "0.31.3",
26
- "@opentelemetry/instrumentation-express": "0.32.2",
25
+ "@opentelemetry/instrumentation-dns": "0.31.5",
26
+ "@opentelemetry/instrumentation-express": "0.32.4",
27
27
  "@opentelemetry/instrumentation-http": "0.38.0",
28
- "@opentelemetry/instrumentation-winston": "0.31.2",
28
+ "@opentelemetry/instrumentation-winston": "0.31.4",
29
29
  "@opentelemetry/sdk-node": "0.38.0",
30
30
  "@opentelemetry/sdk-trace-node": "1.12.0",
31
31
  "axios": "1.4.0",
32
32
  "content-disposition-parser": "1.0.2",
33
- "date-and-time": "3.0.0",
33
+ "date-and-time": "3.0.2",
34
34
  "winston": "3.8.2",
35
35
  "zod": "3.21.4"
36
36
  },
37
37
  "devDependencies": {
38
- "@types/jest": "29.5.1",
39
- "@types/node": "18.16.3",
40
- "@typescript-eslint/eslint-plugin": "5.59.2",
41
- "@typescript-eslint/parser": "5.59.2",
42
- "eslint": "8.39.0",
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
43
  "eslint-config-airbnb-typescript": "17.0.0",
44
44
  "eslint-config-prettier": "8.8.0",
45
45
  "eslint-plugin-import": "2.27.5",
@@ -48,10 +48,10 @@
48
48
  "jest": "29.5.0",
49
49
  "jest-mock-extended": "3.0.4",
50
50
  "jest-sonar-reporter": "2.0.0",
51
- "lint-staged": "13.2.2",
52
- "nock": "13.3.1",
51
+ "lint-staged": "13.2.3",
52
+ "nock": "13.3.2",
53
53
  "prettier": "2.8.8",
54
- "ts-jest": "29.1.0",
54
+ "ts-jest": "29.1.1",
55
55
  "ts-node": "10.9.1",
56
56
  "typescript": "5.0.4"
57
57
  },