@moreapp/common-nodejs 0.2.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/.eslintignore +2 -0
- package/.eslintrc.json +19 -0
- package/.husky/pre-commit +5 -0
- package/.nvmrc +1 -0
- package/.prettierignore +1 -0
- package/README.md +12 -0
- package/bitbucket-pipelines.yml +53 -0
- package/build/jest.config.d.ts +3 -0
- package/build/jest.config.js +13 -0
- package/build/src/index.d.ts +1 -0
- package/build/src/index.js +17 -0
- package/build/src/utils.d.ts +1 -0
- package/build/src/utils.js +11 -0
- package/build/src/utils.test.d.ts +1 -0
- package/build/src/utils.test.js +15 -0
- package/jest.config.ts +14 -0
- package/package.json +48 -0
- package/sonar-project.properties +5 -0
- package/src/index.ts +1 -0
- package/src/utils.test.ts +20 -0
- package/src/utils.ts +8 -0
- package/tsconfig.json +24 -0
package/.eslintignore
ADDED
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"env": {
|
|
3
|
+
"node": true
|
|
4
|
+
},
|
|
5
|
+
"extends": ["plugin:prettier/recommended"],
|
|
6
|
+
"parser": "@typescript-eslint/parser",
|
|
7
|
+
"parserOptions": {
|
|
8
|
+
"project": ["./tsconfig.json"],
|
|
9
|
+
"ecmaVersion": 12,
|
|
10
|
+
"sourceType": "module"
|
|
11
|
+
},
|
|
12
|
+
"plugins": ["prettier", "@typescript-eslint"],
|
|
13
|
+
"rules": {
|
|
14
|
+
"prettier/prettier": ["error"],
|
|
15
|
+
"default-case": "off",
|
|
16
|
+
"@typescript-eslint/switch-exhaustiveness-check": "error"
|
|
17
|
+
},
|
|
18
|
+
"ignorePatterns": ["build"]
|
|
19
|
+
}
|
package/.nvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
18.12.0
|
package/.prettierignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
dist
|
package/README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Notification service
|
|
2
|
+
|
|
3
|
+
# Direnv
|
|
4
|
+
|
|
5
|
+
`direnv` loads the `.envrc` file automatically
|
|
6
|
+
This loads Sparkpost secrets via `kubectl`
|
|
7
|
+
|
|
8
|
+
**NOTE:** make sure the dev-cluster in `kubectx` is named `dev`!
|
|
9
|
+
|
|
10
|
+
# Pre-commit hooks
|
|
11
|
+
|
|
12
|
+
Run `yarn prepare` once to install Git hooks, doing lints and prettier formatting
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
image: node:18.12.0
|
|
2
|
+
|
|
3
|
+
pipelines:
|
|
4
|
+
pull-requests:
|
|
5
|
+
'**':
|
|
6
|
+
- step:
|
|
7
|
+
name: Analyse
|
|
8
|
+
services:
|
|
9
|
+
- docker
|
|
10
|
+
caches:
|
|
11
|
+
- docker
|
|
12
|
+
- node
|
|
13
|
+
- sonar
|
|
14
|
+
script:
|
|
15
|
+
- yarn install --frozen-lockfile
|
|
16
|
+
- yarn format:check
|
|
17
|
+
- yarn lint:check
|
|
18
|
+
- yarn build
|
|
19
|
+
- yarn test --coverage --testResultsProcessor=jest-sonar-reporter --detectOpenHandles
|
|
20
|
+
- pipe: sonarsource/sonarcloud-scan:1.4.0
|
|
21
|
+
variables:
|
|
22
|
+
EXTRA_ARGS: '-Dsonar.sources=src -Dsonar.tests=src -Dsonar.test.inclusions="**/*.test.js" -Dsonar.coverage.exclusions="**/node_modules/**,**/*.spec.ts" -Dsonar.javascript.lcov.reportPaths=coverage/lcov.info'
|
|
23
|
+
- pipe: sonarsource/sonarcloud-quality-gate:0.1.6
|
|
24
|
+
branches:
|
|
25
|
+
master:
|
|
26
|
+
- step:
|
|
27
|
+
name: "Build"
|
|
28
|
+
caches:
|
|
29
|
+
- node
|
|
30
|
+
script:
|
|
31
|
+
- yarn --frozen-lockfile
|
|
32
|
+
- yarn build
|
|
33
|
+
artifacts:
|
|
34
|
+
- build/**
|
|
35
|
+
- step:
|
|
36
|
+
name: "Publish to NPM"
|
|
37
|
+
trigger: manual
|
|
38
|
+
caches:
|
|
39
|
+
- node
|
|
40
|
+
script:
|
|
41
|
+
- npm version minor -m "Upgrade to %s [skip ci]"
|
|
42
|
+
- git push && git push --tags
|
|
43
|
+
- pipe: atlassian/npm-publish:0.3.2
|
|
44
|
+
variables:
|
|
45
|
+
NPM_TOKEN: $NPM_TOKEN
|
|
46
|
+
EXTRA_ARGS: "--access public"
|
|
47
|
+
|
|
48
|
+
definitions:
|
|
49
|
+
caches:
|
|
50
|
+
sonar: ~/.sonar/cache
|
|
51
|
+
services:
|
|
52
|
+
docker:
|
|
53
|
+
memory: 2048
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const config = {
|
|
4
|
+
verbose: true,
|
|
5
|
+
preset: "ts-jest",
|
|
6
|
+
testEnvironment: "node",
|
|
7
|
+
testPathIgnorePatterns: ["/node_modules/", "/dist/"],
|
|
8
|
+
roots: ["<rootDir>/src"],
|
|
9
|
+
transform: {
|
|
10
|
+
"^.+\\.ts?$": "ts-jest",
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
exports.default = config;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./utils";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./utils"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function environmentVariable(key: string, fallback?: string | number): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.environmentVariable = void 0;
|
|
4
|
+
function environmentVariable(key, fallback) {
|
|
5
|
+
const value = process.env[key] || fallback;
|
|
6
|
+
if (value) {
|
|
7
|
+
return value.toString();
|
|
8
|
+
}
|
|
9
|
+
throw new Error(`Missing environment variable '${key}'`);
|
|
10
|
+
}
|
|
11
|
+
exports.environmentVariable = environmentVariable;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("./utils");
|
|
4
|
+
describe("environmentVariable", () => {
|
|
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");
|
|
8
|
+
});
|
|
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");
|
|
11
|
+
});
|
|
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'");
|
|
14
|
+
});
|
|
15
|
+
});
|
package/jest.config.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Config } from "@jest/types";
|
|
2
|
+
|
|
3
|
+
const config: Config.InitialOptions = {
|
|
4
|
+
verbose: true,
|
|
5
|
+
preset: "ts-jest",
|
|
6
|
+
testEnvironment: "node",
|
|
7
|
+
testPathIgnorePatterns: ["/node_modules/", "/dist/"],
|
|
8
|
+
roots: ["<rootDir>/src"],
|
|
9
|
+
transform: {
|
|
10
|
+
"^.+\\.ts?$": "ts-jest",
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default config;
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@moreapp/common-nodejs",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"license": "UNLICENSED",
|
|
5
|
+
"main": "build/index.js",
|
|
6
|
+
"types": "build/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"test": "jest",
|
|
10
|
+
"prettier": "prettier './**/*.{ts,json,yaml,md,}'",
|
|
11
|
+
"format:check": "yarn prettier --check",
|
|
12
|
+
"format:fix": "yarn prettier --write",
|
|
13
|
+
"lint:check": "eslint . --ext ts",
|
|
14
|
+
"lint:fix": "yarn lint:check --fix",
|
|
15
|
+
"prepare": "husky install"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/jest": "29.2.0",
|
|
20
|
+
"@types/node": "18.11.8",
|
|
21
|
+
"@typescript-eslint/eslint-plugin": "5.41.0",
|
|
22
|
+
"@typescript-eslint/parser": "5.41.0",
|
|
23
|
+
"eslint": "8.26.0",
|
|
24
|
+
"eslint-config-airbnb-typescript": "17.0.0",
|
|
25
|
+
"eslint-config-prettier": "8.5.0",
|
|
26
|
+
"eslint-plugin-import": "2.26.0",
|
|
27
|
+
"eslint-plugin-prettier": "4.2.1",
|
|
28
|
+
"husky": "8.0.1",
|
|
29
|
+
"jest": "29.2.2",
|
|
30
|
+
"jest-mock-extended": "3.0.1",
|
|
31
|
+
"jest-sonar-reporter": "2.0.0",
|
|
32
|
+
"lint-staged": "13.0.3",
|
|
33
|
+
"prettier": "2.7.1",
|
|
34
|
+
"ts-jest": "29.0.3",
|
|
35
|
+
"ts-node": "10.9.1",
|
|
36
|
+
"typescript": "4.8.4"
|
|
37
|
+
},
|
|
38
|
+
"prettier": {
|
|
39
|
+
"printWidth": 100,
|
|
40
|
+
"singleQuote": false
|
|
41
|
+
},
|
|
42
|
+
"lint-staged": {
|
|
43
|
+
"src/**/*.ts": [
|
|
44
|
+
"yarn format:fix",
|
|
45
|
+
"yarn lint:fix"
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./utils";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { environmentVariable } from "./utils";
|
|
2
|
+
|
|
3
|
+
describe("environmentVariable", () => {
|
|
4
|
+
test("Should throw when environment variable does not exist", async () => {
|
|
5
|
+
process.env["COMMONS_NODEJS_TEST_EXISTING"] = "SOME_VALUE";
|
|
6
|
+
expect(environmentVariable("COMMONS_NODEJS_TEST_EXISTING")).toBe("SOME_VALUE");
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
test("Use fallback value when environment variable does not exist", async () => {
|
|
10
|
+
expect(environmentVariable("COMMONS_NODEJS_TEST_NON_EXISTING", "DEFAULT_VALUE")).toBe(
|
|
11
|
+
"DEFAULT_VALUE"
|
|
12
|
+
);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test("Should throw when environment variable does not exist", async () => {
|
|
16
|
+
expect(() => environmentVariable("COMMONS_NODEJS_TEST_NON_EXISTING")).toThrow(
|
|
17
|
+
"Missing environment variable 'COMMONS_NODEJS_TEST_NON_EXISTING'"
|
|
18
|
+
);
|
|
19
|
+
});
|
|
20
|
+
});
|
package/src/utils.ts
ADDED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
|
4
|
+
|
|
5
|
+
"lib": ["ES2021"],
|
|
6
|
+
"module": "commonjs",
|
|
7
|
+
"target": "ES2021",
|
|
8
|
+
"outDir": "./build",
|
|
9
|
+
"strict": true,
|
|
10
|
+
"declaration": true,
|
|
11
|
+
"noUnusedLocals": true,
|
|
12
|
+
"noUnusedParameters": true,
|
|
13
|
+
"noImplicitReturns": true,
|
|
14
|
+
"noFallthroughCasesInSwitch": true,
|
|
15
|
+
"noUncheckedIndexedAccess": true,
|
|
16
|
+
"noImplicitOverride": true,
|
|
17
|
+
"noPropertyAccessFromIndexSignature": true,
|
|
18
|
+
"esModuleInterop": true,
|
|
19
|
+
"skipLibCheck": true,
|
|
20
|
+
"forceConsistentCasingInFileNames": true,
|
|
21
|
+
// Required to load JSON files
|
|
22
|
+
"resolveJsonModule": true
|
|
23
|
+
}
|
|
24
|
+
}
|