skuba 0.0.0-master-20230318044948
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/LICENSE +21 -0
- package/README.md +67 -0
- package/config/eslint.js +3 -0
- package/config/jest.js +1 -0
- package/config/prettier.d.ts +3 -0
- package/config/prettier.js +5 -0
- package/config/tsconfig.json +9 -0
- package/jest/moduleNameMapper.js +58 -0
- package/jest/moduleNameMapper.test.ts +64 -0
- package/jest/transform.js +50 -0
- package/jest/transform.test.ts +11 -0
- package/jest/tsConfig.js +26 -0
- package/jest-preset.js +34 -0
- package/lib/api/buildkite/annotate.d.ts +26 -0
- package/lib/api/buildkite/annotate.js +49 -0
- package/lib/api/buildkite/annotate.js.map +7 -0
- package/lib/api/buildkite/index.d.ts +3 -0
- package/lib/api/buildkite/index.js +32 -0
- package/lib/api/buildkite/index.js.map +7 -0
- package/lib/api/buildkite/md.d.ts +6 -0
- package/lib/api/buildkite/md.js +33 -0
- package/lib/api/buildkite/md.js.map +7 -0
- package/lib/api/git/commit.d.ts +15 -0
- package/lib/api/git/commit.js +52 -0
- package/lib/api/git/commit.js.map +7 -0
- package/lib/api/git/commitAllChanges.d.ts +19 -0
- package/lib/api/git/commitAllChanges.js +65 -0
- package/lib/api/git/commitAllChanges.js.map +7 -0
- package/lib/api/git/currentBranch.d.ts +10 -0
- package/lib/api/git/currentBranch.js +58 -0
- package/lib/api/git/currentBranch.js.map +7 -0
- package/lib/api/git/getChangedFiles.d.ts +20 -0
- package/lib/api/git/getChangedFiles.js +63 -0
- package/lib/api/git/getChangedFiles.js.map +7 -0
- package/lib/api/git/index.d.ts +10 -0
- package/lib/api/git/index.js +55 -0
- package/lib/api/git/index.js.map +7 -0
- package/lib/api/git/log.d.ts +19 -0
- package/lib/api/git/log.js +71 -0
- package/lib/api/git/log.js.map +7 -0
- package/lib/api/git/pull.d.ts +35 -0
- package/lib/api/git/pull.js +69 -0
- package/lib/api/git/pull.js.map +7 -0
- package/lib/api/git/push.d.ts +43 -0
- package/lib/api/git/push.js +70 -0
- package/lib/api/git/push.js.map +7 -0
- package/lib/api/git/remote.d.ts +20 -0
- package/lib/api/git/remote.js +72 -0
- package/lib/api/git/remote.js.map +7 -0
- package/lib/api/git/reset.d.ts +12 -0
- package/lib/api/git/reset.js +62 -0
- package/lib/api/git/reset.js.map +7 -0
- package/lib/api/git/statusMatrix.d.ts +7 -0
- package/lib/api/git/statusMatrix.js +47 -0
- package/lib/api/git/statusMatrix.js.map +7 -0
- package/lib/api/github/checkRun.d.ts +44 -0
- package/lib/api/github/checkRun.js +81 -0
- package/lib/api/github/checkRun.js.map +7 -0
- package/lib/api/github/environment.d.ts +18 -0
- package/lib/api/github/environment.js +48 -0
- package/lib/api/github/environment.js.map +7 -0
- package/lib/api/github/index.d.ts +7 -0
- package/lib/api/github/index.js +48 -0
- package/lib/api/github/index.js.map +7 -0
- package/lib/api/github/issueComment.d.ts +59 -0
- package/lib/api/github/issueComment.js +83 -0
- package/lib/api/github/issueComment.js.map +7 -0
- package/lib/api/github/pullRequest.d.ts +21 -0
- package/lib/api/github/pullRequest.js +68 -0
- package/lib/api/github/pullRequest.js.map +7 -0
- package/lib/api/github/push.d.ts +79 -0
- package/lib/api/github/push.js +158 -0
- package/lib/api/github/push.js.map +7 -0
- package/lib/api/jest/index.d.ts +144 -0
- package/lib/api/jest/index.js +41 -0
- package/lib/api/jest/index.js.map +7 -0
- package/lib/api/net/compose.d.ts +4 -0
- package/lib/api/net/compose.js +50 -0
- package/lib/api/net/compose.js.map +7 -0
- package/lib/api/net/index.d.ts +1 -0
- package/lib/api/net/index.js +29 -0
- package/lib/api/net/index.js.map +7 -0
- package/lib/api/net/socket.d.ts +5 -0
- package/lib/api/net/socket.js +68 -0
- package/lib/api/net/socket.js.map +7 -0
- package/lib/api/net/waitFor.d.ts +22 -0
- package/lib/api/net/waitFor.js +40 -0
- package/lib/api/net/waitFor.js.map +7 -0
- package/lib/cli/adapter/eslint.d.ts +14 -0
- package/lib/cli/adapter/eslint.js +112 -0
- package/lib/cli/adapter/eslint.js.map +7 -0
- package/lib/cli/adapter/prettier.d.ts +45 -0
- package/lib/cli/adapter/prettier.js +171 -0
- package/lib/cli/adapter/prettier.js.map +7 -0
- package/lib/cli/build/args.d.ts +7 -0
- package/lib/cli/build/args.js +73 -0
- package/lib/cli/build/args.js.map +7 -0
- package/lib/cli/build/esbuild.d.ts +5 -0
- package/lib/cli/build/esbuild.js +133 -0
- package/lib/cli/build/esbuild.js.map +7 -0
- package/lib/cli/build/index.d.ts +1 -0
- package/lib/cli/build/index.js +73 -0
- package/lib/cli/build/index.js.map +7 -0
- package/lib/cli/build/tsc.d.ts +1 -0
- package/lib/cli/build/tsc.js +36 -0
- package/lib/cli/build/tsc.js.map +7 -0
- package/lib/cli/buildPackage.d.ts +1 -0
- package/lib/cli/buildPackage.js +56 -0
- package/lib/cli/buildPackage.js.map +7 -0
- package/lib/cli/configure/addEmptyExports.d.ts +6 -0
- package/lib/cli/configure/addEmptyExports.js +76 -0
- package/lib/cli/configure/addEmptyExports.js.map +7 -0
- package/lib/cli/configure/analyseConfiguration.d.ts +9 -0
- package/lib/cli/configure/analyseConfiguration.js +69 -0
- package/lib/cli/configure/analyseConfiguration.js.map +7 -0
- package/lib/cli/configure/analyseDependencies.d.ts +10 -0
- package/lib/cli/configure/analyseDependencies.js +136 -0
- package/lib/cli/configure/analyseDependencies.js.map +7 -0
- package/lib/cli/configure/analysis/diff.d.ts +1 -0
- package/lib/cli/configure/analysis/diff.js +45 -0
- package/lib/cli/configure/analysis/diff.js.map +7 -0
- package/lib/cli/configure/analysis/files.d.ts +1 -0
- package/lib/cli/configure/analysis/files.js +58 -0
- package/lib/cli/configure/analysis/files.js.map +7 -0
- package/lib/cli/configure/analysis/git.d.ts +1 -0
- package/lib/cli/configure/analysis/git.js +54 -0
- package/lib/cli/configure/analysis/git.js.map +7 -0
- package/lib/cli/configure/analysis/package.d.ts +13 -0
- package/lib/cli/configure/analysis/package.js +110 -0
- package/lib/cli/configure/analysis/package.js.map +7 -0
- package/lib/cli/configure/analysis/project.d.ts +3 -0
- package/lib/cli/configure/analysis/project.js +105 -0
- package/lib/cli/configure/analysis/project.js.map +7 -0
- package/lib/cli/configure/dependencies/index.d.ts +5 -0
- package/lib/cli/configure/dependencies/index.js +41 -0
- package/lib/cli/configure/dependencies/index.js.map +7 -0
- package/lib/cli/configure/dependencies/seekDatadogCustomMetrics.d.ts +2 -0
- package/lib/cli/configure/dependencies/seekDatadogCustomMetrics.js +59 -0
- package/lib/cli/configure/dependencies/seekDatadogCustomMetrics.js.map +7 -0
- package/lib/cli/configure/dependencies/seekKoala.d.ts +2 -0
- package/lib/cli/configure/dependencies/seekKoala.js +56 -0
- package/lib/cli/configure/dependencies/seekKoala.js.map +7 -0
- package/lib/cli/configure/dependencies/skuba.d.ts +2 -0
- package/lib/cli/configure/dependencies/skuba.js +52 -0
- package/lib/cli/configure/dependencies/skuba.js.map +7 -0
- package/lib/cli/configure/dependencies/skubaDeps.d.ts +2 -0
- package/lib/cli/configure/dependencies/skubaDeps.js +56 -0
- package/lib/cli/configure/dependencies/skubaDeps.js.map +7 -0
- package/lib/cli/configure/dependencies/skubaDive.d.ts +3 -0
- package/lib/cli/configure/dependencies/skubaDive.js +70 -0
- package/lib/cli/configure/dependencies/skubaDive.js.map +7 -0
- package/lib/cli/configure/ensureTemplateCompletion.d.ts +9 -0
- package/lib/cli/configure/ensureTemplateCompletion.js +77 -0
- package/lib/cli/configure/ensureTemplateCompletion.js.map +7 -0
- package/lib/cli/configure/getEntryPoint.d.ts +11 -0
- package/lib/cli/configure/getEntryPoint.js +70 -0
- package/lib/cli/configure/getEntryPoint.js.map +7 -0
- package/lib/cli/configure/getProjectType.d.ts +9 -0
- package/lib/cli/configure/getProjectType.js +52 -0
- package/lib/cli/configure/getProjectType.js.map +7 -0
- package/lib/cli/configure/index.d.ts +1 -0
- package/lib/cli/configure/index.js +148 -0
- package/lib/cli/configure/index.js.map +7 -0
- package/lib/cli/configure/modules/eslint.d.ts +2 -0
- package/lib/cli/configure/modules/eslint.js +61 -0
- package/lib/cli/configure/modules/eslint.js.map +7 -0
- package/lib/cli/configure/modules/ignore.d.ts +2 -0
- package/lib/cli/configure/modules/ignore.js +40 -0
- package/lib/cli/configure/modules/ignore.js.map +7 -0
- package/lib/cli/configure/modules/index.d.ts +2 -0
- package/lib/cli/configure/modules/index.js +54 -0
- package/lib/cli/configure/modules/index.js.map +7 -0
- package/lib/cli/configure/modules/jest.d.ts +2 -0
- package/lib/cli/configure/modules/jest.js +86 -0
- package/lib/cli/configure/modules/jest.js.map +7 -0
- package/lib/cli/configure/modules/nodemon.d.ts +2 -0
- package/lib/cli/configure/modules/nodemon.js +30 -0
- package/lib/cli/configure/modules/nodemon.js.map +7 -0
- package/lib/cli/configure/modules/package.d.ts +2 -0
- package/lib/cli/configure/modules/package.js +117 -0
- package/lib/cli/configure/modules/package.js.map +7 -0
- package/lib/cli/configure/modules/prettier.d.ts +2 -0
- package/lib/cli/configure/modules/prettier.js +52 -0
- package/lib/cli/configure/modules/prettier.js.map +7 -0
- package/lib/cli/configure/modules/renovate.d.ts +3 -0
- package/lib/cli/configure/modules/renovate.js +69 -0
- package/lib/cli/configure/modules/renovate.js.map +7 -0
- package/lib/cli/configure/modules/serverless.d.ts +2 -0
- package/lib/cli/configure/modules/serverless.js +36 -0
- package/lib/cli/configure/modules/serverless.js.map +7 -0
- package/lib/cli/configure/modules/skubaDive.d.ts +2 -0
- package/lib/cli/configure/modules/skubaDive.js +72 -0
- package/lib/cli/configure/modules/skubaDive.js.map +7 -0
- package/lib/cli/configure/modules/tsconfig.d.ts +2 -0
- package/lib/cli/configure/modules/tsconfig.js +87 -0
- package/lib/cli/configure/modules/tsconfig.js.map +7 -0
- package/lib/cli/configure/modules/tslint.d.ts +2 -0
- package/lib/cli/configure/modules/tslint.js +30 -0
- package/lib/cli/configure/modules/tslint.js.map +7 -0
- package/lib/cli/configure/patchRenovateConfig.d.ts +1 -0
- package/lib/cli/configure/patchRenovateConfig.js +132 -0
- package/lib/cli/configure/patchRenovateConfig.js.map +7 -0
- package/lib/cli/configure/processing/deleteFiles.d.ts +5 -0
- package/lib/cli/configure/processing/deleteFiles.js +31 -0
- package/lib/cli/configure/processing/deleteFiles.js.map +7 -0
- package/lib/cli/configure/processing/ignoreFile.d.ts +8 -0
- package/lib/cli/configure/processing/ignoreFile.js +74 -0
- package/lib/cli/configure/processing/ignoreFile.js.map +7 -0
- package/lib/cli/configure/processing/javascript.d.ts +2 -0
- package/lib/cli/configure/processing/javascript.js +38 -0
- package/lib/cli/configure/processing/javascript.js.map +7 -0
- package/lib/cli/configure/processing/json.d.ts +2 -0
- package/lib/cli/configure/processing/json.js +57 -0
- package/lib/cli/configure/processing/json.js.map +7 -0
- package/lib/cli/configure/processing/loadFiles.d.ts +5 -0
- package/lib/cli/configure/processing/loadFiles.js +31 -0
- package/lib/cli/configure/processing/loadFiles.js.map +7 -0
- package/lib/cli/configure/processing/module.d.ts +10 -0
- package/lib/cli/configure/processing/module.js +39 -0
- package/lib/cli/configure/processing/module.js.map +7 -0
- package/lib/cli/configure/processing/package.d.ts +73 -0
- package/lib/cli/configure/processing/package.js +87 -0
- package/lib/cli/configure/processing/package.js.map +7 -0
- package/lib/cli/configure/processing/prettier.d.ts +4 -0
- package/lib/cli/configure/processing/prettier.js +44 -0
- package/lib/cli/configure/processing/prettier.js.map +7 -0
- package/lib/cli/configure/processing/record.d.ts +11 -0
- package/lib/cli/configure/processing/record.js +65 -0
- package/lib/cli/configure/processing/record.js.map +7 -0
- package/lib/cli/configure/processing/typescript.d.ts +23 -0
- package/lib/cli/configure/processing/typescript.js +197 -0
- package/lib/cli/configure/processing/typescript.js.map +7 -0
- package/lib/cli/configure/refreshIgnoreFiles.d.ts +3 -0
- package/lib/cli/configure/refreshIgnoreFiles.js +78 -0
- package/lib/cli/configure/refreshIgnoreFiles.js.map +7 -0
- package/lib/cli/configure/types.d.ts +26 -0
- package/lib/cli/configure/types.js +17 -0
- package/lib/cli/configure/types.js.map +7 -0
- package/lib/cli/format.d.ts +1 -0
- package/lib/cli/format.js +70 -0
- package/lib/cli/format.js.map +7 -0
- package/lib/cli/help.d.ts +1 -0
- package/lib/cli/help.js +34 -0
- package/lib/cli/help.js.map +7 -0
- package/lib/cli/init/getConfig.d.ts +26 -0
- package/lib/cli/init/getConfig.js +285 -0
- package/lib/cli/init/getConfig.js.map +7 -0
- package/lib/cli/init/git.d.ts +7 -0
- package/lib/cli/init/git.js +82 -0
- package/lib/cli/init/git.js.map +7 -0
- package/lib/cli/init/index.d.ts +1 -0
- package/lib/cli/init/index.js +146 -0
- package/lib/cli/init/index.js.map +7 -0
- package/lib/cli/init/prompts.d.ts +45 -0
- package/lib/cli/init/prompts.js +97 -0
- package/lib/cli/init/prompts.js.map +7 -0
- package/lib/cli/init/types.d.ts +28 -0
- package/lib/cli/init/types.js +65 -0
- package/lib/cli/init/types.js.map +7 -0
- package/lib/cli/init/validation.d.ts +8 -0
- package/lib/cli/init/validation.js +43 -0
- package/lib/cli/init/validation.js.map +7 -0
- package/lib/cli/init/writePackageJson.d.ts +13 -0
- package/lib/cli/init/writePackageJson.js +58 -0
- package/lib/cli/init/writePackageJson.js.map +7 -0
- package/lib/cli/lint/annotate/buildkite/eslint.d.ts +2 -0
- package/lib/cli/lint/annotate/buildkite/eslint.js +40 -0
- package/lib/cli/lint/annotate/buildkite/eslint.js.map +7 -0
- package/lib/cli/lint/annotate/buildkite/index.d.ts +4 -0
- package/lib/cli/lint/annotate/buildkite/index.js +58 -0
- package/lib/cli/lint/annotate/buildkite/index.js.map +7 -0
- package/lib/cli/lint/annotate/buildkite/prettier.d.ts +2 -0
- package/lib/cli/lint/annotate/buildkite/prettier.js +47 -0
- package/lib/cli/lint/annotate/buildkite/prettier.js.map +7 -0
- package/lib/cli/lint/annotate/buildkite/tsc.d.ts +2 -0
- package/lib/cli/lint/annotate/buildkite/tsc.js +45 -0
- package/lib/cli/lint/annotate/buildkite/tsc.js.map +7 -0
- package/lib/cli/lint/annotate/github/eslint.d.ts +3 -0
- package/lib/cli/lint/annotate/github/eslint.js +45 -0
- package/lib/cli/lint/annotate/github/eslint.js.map +7 -0
- package/lib/cli/lint/annotate/github/index.d.ts +4 -0
- package/lib/cli/lint/annotate/github/index.js +63 -0
- package/lib/cli/lint/annotate/github/index.js.map +7 -0
- package/lib/cli/lint/annotate/github/prettier.d.ts +3 -0
- package/lib/cli/lint/annotate/github/prettier.js +39 -0
- package/lib/cli/lint/annotate/github/prettier.js.map +7 -0
- package/lib/cli/lint/annotate/github/tsc.d.ts +3 -0
- package/lib/cli/lint/annotate/github/tsc.js +63 -0
- package/lib/cli/lint/annotate/github/tsc.js.map +7 -0
- package/lib/cli/lint/annotate/index.d.ts +4 -0
- package/lib/cli/lint/annotate/index.js +36 -0
- package/lib/cli/lint/annotate/index.js.map +7 -0
- package/lib/cli/lint/autofix.d.ts +10 -0
- package/lib/cli/lint/autofix.js +189 -0
- package/lib/cli/lint/autofix.js.map +7 -0
- package/lib/cli/lint/eslint.d.ts +4 -0
- package/lib/cli/lint/eslint.js +55 -0
- package/lib/cli/lint/eslint.js.map +7 -0
- package/lib/cli/lint/external.d.ts +10 -0
- package/lib/cli/lint/external.js +120 -0
- package/lib/cli/lint/external.js.map +7 -0
- package/lib/cli/lint/index.d.ts +2 -0
- package/lib/cli/lint/index.js +49 -0
- package/lib/cli/lint/index.js.map +7 -0
- package/lib/cli/lint/internal.d.ts +1 -0
- package/lib/cli/lint/internal.js +64 -0
- package/lib/cli/lint/internal.js.map +7 -0
- package/lib/cli/lint/prettier.d.ts +4 -0
- package/lib/cli/lint/prettier.js +55 -0
- package/lib/cli/lint/prettier.js.map +7 -0
- package/lib/cli/lint/tsc.d.ts +2 -0
- package/lib/cli/lint/tsc.js +58 -0
- package/lib/cli/lint/tsc.js.map +7 -0
- package/lib/cli/lint/types.d.ts +34 -0
- package/lib/cli/lint/types.js +17 -0
- package/lib/cli/lint/types.js.map +7 -0
- package/lib/cli/node.d.ts +1 -0
- package/lib/cli/node.js +77 -0
- package/lib/cli/node.js.map +7 -0
- package/lib/cli/release.d.ts +1 -0
- package/lib/cli/release.js +32 -0
- package/lib/cli/release.js.map +7 -0
- package/lib/cli/start.d.ts +1 -0
- package/lib/cli/start.js +69 -0
- package/lib/cli/start.js.map +7 -0
- package/lib/cli/test/index.d.ts +1 -0
- package/lib/cli/test/index.js +37 -0
- package/lib/cli/test/index.js.map +7 -0
- package/lib/cli/test/reporters/github/annotations.d.ts +9 -0
- package/lib/cli/test/reporters/github/annotations.js +102 -0
- package/lib/cli/test/reporters/github/annotations.js.map +7 -0
- package/lib/cli/test/reporters/github/index.d.ts +5 -0
- package/lib/cli/test/reporters/github/index.js +77 -0
- package/lib/cli/test/reporters/github/index.js.map +7 -0
- package/lib/cli/version.d.ts +1 -0
- package/lib/cli/version.js +34 -0
- package/lib/cli/version.js.map +7 -0
- package/lib/enquirer.d.js +2 -0
- package/lib/enquirer.d.js.map +7 -0
- package/lib/index.d.ts +22 -0
- package/lib/index.js +51 -0
- package/lib/index.js.map +7 -0
- package/lib/skuba.d.ts +11 -0
- package/lib/skuba.js +55 -0
- package/lib/skuba.js.map +7 -0
- package/lib/utils/args.d.ts +43 -0
- package/lib/utils/args.js +114 -0
- package/lib/utils/args.js.map +7 -0
- package/lib/utils/command.d.ts +6 -0
- package/lib/utils/command.js +72 -0
- package/lib/utils/command.js.map +7 -0
- package/lib/utils/copy.d.ts +16 -0
- package/lib/utils/copy.js +100 -0
- package/lib/utils/copy.js.map +7 -0
- package/lib/utils/dir.d.ts +21 -0
- package/lib/utils/dir.js +91 -0
- package/lib/utils/dir.js.map +7 -0
- package/lib/utils/env.d.ts +5 -0
- package/lib/utils/env.js +29 -0
- package/lib/utils/env.js.map +7 -0
- package/lib/utils/error.d.ts +28 -0
- package/lib/utils/error.js +72 -0
- package/lib/utils/error.js.map +7 -0
- package/lib/utils/exec.d.ts +40 -0
- package/lib/utils/exec.js +166 -0
- package/lib/utils/exec.js.map +7 -0
- package/lib/utils/help.d.ts +1 -0
- package/lib/utils/help.js +34 -0
- package/lib/utils/help.js.map +7 -0
- package/lib/utils/logging.d.ts +27 -0
- package/lib/utils/logging.js +60 -0
- package/lib/utils/logging.js.map +7 -0
- package/lib/utils/logo.d.ts +9 -0
- package/lib/utils/logo.js +74 -0
- package/lib/utils/logo.js.map +7 -0
- package/lib/utils/manifest.d.ts +10 -0
- package/lib/utils/manifest.js +77 -0
- package/lib/utils/manifest.js.map +7 -0
- package/lib/utils/port.d.ts +2 -0
- package/lib/utils/port.js +48 -0
- package/lib/utils/port.js.map +7 -0
- package/lib/utils/template.d.ts +37 -0
- package/lib/utils/template.js +116 -0
- package/lib/utils/template.js.map +7 -0
- package/lib/utils/validation.d.ts +6 -0
- package/lib/utils/validation.js +44 -0
- package/lib/utils/validation.js.map +7 -0
- package/lib/utils/version.d.ts +13 -0
- package/lib/utils/version.js +89 -0
- package/lib/utils/version.js.map +7 -0
- package/lib/utils/wait.d.ts +17 -0
- package/lib/utils/wait.js +59 -0
- package/lib/utils/wait.js.map +7 -0
- package/lib/utils/worker.d.ts +20 -0
- package/lib/utils/worker.js +63 -0
- package/lib/utils/worker.js.map +7 -0
- package/lib/wrapper/function-arguments.d.js +2 -0
- package/lib/wrapper/function-arguments.d.js.map +7 -0
- package/lib/wrapper/functionHandler.d.ts +10 -0
- package/lib/wrapper/functionHandler.js +63 -0
- package/lib/wrapper/functionHandler.js.map +7 -0
- package/lib/wrapper/http.d.ts +20 -0
- package/lib/wrapper/http.js +79 -0
- package/lib/wrapper/http.js.map +7 -0
- package/lib/wrapper/index.d.ts +12 -0
- package/lib/wrapper/index.js +16 -0
- package/lib/wrapper/index.js.map +7 -0
- package/lib/wrapper/main.d.ts +1 -0
- package/lib/wrapper/main.js +47 -0
- package/lib/wrapper/main.js.map +7 -0
- package/lib/wrapper/requestListener.d.ts +11 -0
- package/lib/wrapper/requestListener.js +66 -0
- package/lib/wrapper/requestListener.js.map +7 -0
- package/package.json +167 -0
- package/template/base/.github/CODEOWNERS +5 -0
- package/template/base/.github/renovate.json5 +3 -0
- package/template/base/_.dockerignore +18 -0
- package/template/base/_.eslintignore +14 -0
- package/template/base/_.eslintrc.js +3 -0
- package/template/base/_.gitignore +23 -0
- package/template/base/_.prettierignore +20 -0
- package/template/base/_.prettierrc.js +1 -0
- package/template/base/jest.config.ts +15 -0
- package/template/base/jest.setup.ts +3 -0
- package/template/base/tsconfig.build.json +5 -0
- package/template/base/tsconfig.json +13 -0
- package/template/express-rest-api/.buildkite/pipeline.yml +103 -0
- package/template/express-rest-api/.env +1 -0
- package/template/express-rest-api/.gantry/common.yml +20 -0
- package/template/express-rest-api/.gantry/dev.yml +8 -0
- package/template/express-rest-api/.gantry/prod.yml +8 -0
- package/template/express-rest-api/.nvmrc +1 -0
- package/template/express-rest-api/Dockerfile +37 -0
- package/template/express-rest-api/Dockerfile.dev-deps +11 -0
- package/template/express-rest-api/README.md +106 -0
- package/template/express-rest-api/docker-compose.yml +22 -0
- package/template/express-rest-api/gantry.apply.yml +122 -0
- package/template/express-rest-api/gantry.build.yml +15 -0
- package/template/express-rest-api/package.json +30 -0
- package/template/express-rest-api/skuba.template.js +49 -0
- package/template/express-rest-api/src/api/healthCheck.ts +11 -0
- package/template/express-rest-api/src/api/smokeTest.ts +8 -0
- package/template/express-rest-api/src/app.test.ts +9 -0
- package/template/express-rest-api/src/app.ts +14 -0
- package/template/express-rest-api/src/config.ts +57 -0
- package/template/express-rest-api/src/framework/logging.ts +17 -0
- package/template/express-rest-api/src/listen.ts +23 -0
- package/template/express-rest-api/src/register.ts +1 -0
- package/template/greeter/.buildkite/pipeline.yml +37 -0
- package/template/greeter/.nvmrc +1 -0
- package/template/greeter/Dockerfile +11 -0
- package/template/greeter/README.md +96 -0
- package/template/greeter/docker-compose.yml +22 -0
- package/template/greeter/package.json +24 -0
- package/template/greeter/skuba.template.js +16 -0
- package/template/greeter/src/app.test.ts +5 -0
- package/template/greeter/src/app.ts +4 -0
- package/template/koa-rest-api/.buildkite/pipeline.yml +103 -0
- package/template/koa-rest-api/.env +1 -0
- package/template/koa-rest-api/.gantry/common.yml +20 -0
- package/template/koa-rest-api/.gantry/dev.yml +11 -0
- package/template/koa-rest-api/.gantry/prod.yml +11 -0
- package/template/koa-rest-api/.nvmrc +1 -0
- package/template/koa-rest-api/Dockerfile +37 -0
- package/template/koa-rest-api/Dockerfile.dev-deps +11 -0
- package/template/koa-rest-api/README.md +111 -0
- package/template/koa-rest-api/docker-compose.yml +22 -0
- package/template/koa-rest-api/gantry.apply.yml +129 -0
- package/template/koa-rest-api/gantry.build.yml +15 -0
- package/template/koa-rest-api/package.json +47 -0
- package/template/koa-rest-api/skuba.template.js +49 -0
- package/template/koa-rest-api/src/api/healthCheck.ts +13 -0
- package/template/koa-rest-api/src/api/index.ts +10 -0
- package/template/koa-rest-api/src/api/jobs/getJobs.test.ts +9 -0
- package/template/koa-rest-api/src/api/jobs/getJobs.ts +15 -0
- package/template/koa-rest-api/src/api/jobs/index.ts +10 -0
- package/template/koa-rest-api/src/api/jobs/postJob.test.ts +34 -0
- package/template/koa-rest-api/src/api/jobs/postJob.ts +19 -0
- package/template/koa-rest-api/src/api/smokeTest.ts +11 -0
- package/template/koa-rest-api/src/app.test.ts +21 -0
- package/template/koa-rest-api/src/app.ts +8 -0
- package/template/koa-rest-api/src/config.ts +57 -0
- package/template/koa-rest-api/src/framework/logging.ts +25 -0
- package/template/koa-rest-api/src/framework/metrics.ts +11 -0
- package/template/koa-rest-api/src/framework/middleware.ts +3 -0
- package/template/koa-rest-api/src/framework/server.test.ts +260 -0
- package/template/koa-rest-api/src/framework/server.ts +51 -0
- package/template/koa-rest-api/src/framework/validation.test.ts +72 -0
- package/template/koa-rest-api/src/framework/validation.ts +77 -0
- package/template/koa-rest-api/src/listen.ts +24 -0
- package/template/koa-rest-api/src/register.ts +1 -0
- package/template/koa-rest-api/src/storage/jobs.ts +28 -0
- package/template/koa-rest-api/src/testing/logging.ts +16 -0
- package/template/koa-rest-api/src/testing/metrics.ts +29 -0
- package/template/koa-rest-api/src/testing/server.ts +31 -0
- package/template/koa-rest-api/src/testing/types.ts +24 -0
- package/template/koa-rest-api/src/tracing.ts +61 -0
- package/template/koa-rest-api/src/types/jobs.ts +17 -0
- package/template/koa-rest-api/src/types/koa.ts +8 -0
- package/template/lambda-sqs-worker/.buildkite/pipeline.yml +96 -0
- package/template/lambda-sqs-worker/.env +1 -0
- package/template/lambda-sqs-worker/.nvmrc +1 -0
- package/template/lambda-sqs-worker/Dockerfile +12 -0
- package/template/lambda-sqs-worker/README.md +132 -0
- package/template/lambda-sqs-worker/docker-compose.yml +27 -0
- package/template/lambda-sqs-worker/package.json +44 -0
- package/template/lambda-sqs-worker/serverless.yml +202 -0
- package/template/lambda-sqs-worker/skuba.template.js +32 -0
- package/template/lambda-sqs-worker/src/app.test.ts +116 -0
- package/template/lambda-sqs-worker/src/app.ts +52 -0
- package/template/lambda-sqs-worker/src/config.ts +57 -0
- package/template/lambda-sqs-worker/src/framework/handler.test.ts +61 -0
- package/template/lambda-sqs-worker/src/framework/handler.ts +43 -0
- package/template/lambda-sqs-worker/src/framework/logging.ts +27 -0
- package/template/lambda-sqs-worker/src/framework/metrics.ts +14 -0
- package/template/lambda-sqs-worker/src/framework/validation.test.ts +84 -0
- package/template/lambda-sqs-worker/src/framework/validation.ts +10 -0
- package/template/lambda-sqs-worker/src/hooks.ts +96 -0
- package/template/lambda-sqs-worker/src/mapping/jobScorer.ts +19 -0
- package/template/lambda-sqs-worker/src/services/aws.ts +5 -0
- package/template/lambda-sqs-worker/src/services/jobScorer.test.ts +44 -0
- package/template/lambda-sqs-worker/src/services/jobScorer.ts +56 -0
- package/template/lambda-sqs-worker/src/services/pipelineEventSender.test.ts +40 -0
- package/template/lambda-sqs-worker/src/services/pipelineEventSender.ts +33 -0
- package/template/lambda-sqs-worker/src/testing/handler.ts +13 -0
- package/template/lambda-sqs-worker/src/testing/logging.ts +16 -0
- package/template/lambda-sqs-worker/src/testing/services.ts +28 -0
- package/template/lambda-sqs-worker/src/testing/types.ts +33 -0
- package/template/lambda-sqs-worker/src/types/jobScorer.ts +15 -0
- package/template/lambda-sqs-worker/src/types/pipelineEvents.ts +21 -0
- package/template/lambda-sqs-worker/tsconfig.json +13 -0
- package/template/lambda-sqs-worker-cdk/.buildkite/pipeline.yml +93 -0
- package/template/lambda-sqs-worker-cdk/.nvmrc +1 -0
- package/template/lambda-sqs-worker-cdk/Dockerfile +13 -0
- package/template/lambda-sqs-worker-cdk/cdk.json +25 -0
- package/template/lambda-sqs-worker-cdk/docker-compose.yml +28 -0
- package/template/lambda-sqs-worker-cdk/infra/__snapshots__/appStack.test.ts.snap +723 -0
- package/template/lambda-sqs-worker-cdk/infra/appStack.test.ts +34 -0
- package/template/lambda-sqs-worker-cdk/infra/appStack.ts +74 -0
- package/template/lambda-sqs-worker-cdk/infra/index.ts +14 -0
- package/template/lambda-sqs-worker-cdk/package.json +30 -0
- package/template/lambda-sqs-worker-cdk/shared/context-types.ts +21 -0
- package/template/lambda-sqs-worker-cdk/skuba.template.js +27 -0
- package/template/lambda-sqs-worker-cdk/src/app.ts +10 -0
- package/template/lambda-sqs-worker-cdk/tsconfig.json +13 -0
- package/template/oss-npm-package/.github/workflows/release.yml +35 -0
- package/template/oss-npm-package/.github/workflows/validate.yml +31 -0
- package/template/oss-npm-package/.nvmrc +1 -0
- package/template/oss-npm-package/LICENSE +21 -0
- package/template/oss-npm-package/README.md +128 -0
- package/template/oss-npm-package/_package.json +41 -0
- package/template/oss-npm-package/skuba.template.js +22 -0
- package/template/oss-npm-package/src/index.test.ts +5 -0
- package/template/oss-npm-package/src/index.ts +7 -0
- package/template/oss-npm-package/tsconfig.json +10 -0
- package/template/private-npm-package/.buildkite/pipeline.yml +5 -0
- package/template/private-npm-package/.nvmrc +1 -0
- package/template/private-npm-package/README.md +109 -0
- package/template/private-npm-package/_package.json +41 -0
- package/template/private-npm-package/skuba.template.js +24 -0
- package/template/private-npm-package/src/index.test.ts +5 -0
- package/template/private-npm-package/src/index.ts +7 -0
- package/template/private-npm-package/tsconfig.json +10 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import Router from '@koa/router';
|
|
2
|
+
|
|
3
|
+
import { logger } from 'src/testing/logging';
|
|
4
|
+
import { metricsClient } from 'src/testing/metrics';
|
|
5
|
+
import { agentFromRouter } from 'src/testing/server';
|
|
6
|
+
import { chance } from 'src/testing/types';
|
|
7
|
+
import { Middleware } from 'src/types/koa';
|
|
8
|
+
|
|
9
|
+
const middleware = jest.fn<void, Parameters<Middleware>>();
|
|
10
|
+
|
|
11
|
+
const router = new Router()
|
|
12
|
+
.use('/nested', new Router().put('/:param', middleware).routes())
|
|
13
|
+
.get('/', middleware);
|
|
14
|
+
|
|
15
|
+
const agent = agentFromRouter(router);
|
|
16
|
+
|
|
17
|
+
describe('createApp', () => {
|
|
18
|
+
beforeAll(logger.spy);
|
|
19
|
+
|
|
20
|
+
afterEach(metricsClient.clear);
|
|
21
|
+
afterEach(logger.clear);
|
|
22
|
+
|
|
23
|
+
it('handles root route', async () => {
|
|
24
|
+
middleware.mockImplementation((ctx) => (ctx.body = ''));
|
|
25
|
+
|
|
26
|
+
await agent
|
|
27
|
+
.get('/')
|
|
28
|
+
.expect(200, '')
|
|
29
|
+
.expect('server', /.+/)
|
|
30
|
+
.expect('x-api-version', /.+/);
|
|
31
|
+
|
|
32
|
+
expect(logger.error).not.toHaveBeenCalled();
|
|
33
|
+
|
|
34
|
+
expect(logger.info).not.toHaveBeenCalled();
|
|
35
|
+
|
|
36
|
+
metricsClient.expectTagSubset(['env:test', 'version:test']);
|
|
37
|
+
metricsClient.expectTagSubset([
|
|
38
|
+
'http_method:get',
|
|
39
|
+
'http_status:200',
|
|
40
|
+
'http_status_family:2xx',
|
|
41
|
+
'route:/',
|
|
42
|
+
]);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('handles nested route', async () => {
|
|
46
|
+
middleware.mockImplementation((ctx) => (ctx.body = ''));
|
|
47
|
+
|
|
48
|
+
await agent
|
|
49
|
+
.put('/nested/123')
|
|
50
|
+
.expect(200, '')
|
|
51
|
+
.expect('server', /.+/)
|
|
52
|
+
.expect('x-api-version', /.+/);
|
|
53
|
+
|
|
54
|
+
expect(logger.error).not.toHaveBeenCalled();
|
|
55
|
+
|
|
56
|
+
expect(logger.info).not.toHaveBeenCalled();
|
|
57
|
+
|
|
58
|
+
metricsClient.expectTagSubset([
|
|
59
|
+
'http_method:put',
|
|
60
|
+
'http_status:200',
|
|
61
|
+
'http_status_family:2xx',
|
|
62
|
+
'route:/nested/_param',
|
|
63
|
+
]);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('handles unknown route', async () => {
|
|
67
|
+
middleware.mockImplementation((ctx) => (ctx.body = ''));
|
|
68
|
+
|
|
69
|
+
await agent
|
|
70
|
+
.get('/unknown')
|
|
71
|
+
.expect(404, 'Not Found')
|
|
72
|
+
.expect('server', /.+/)
|
|
73
|
+
.expect('x-api-version', /.+/);
|
|
74
|
+
|
|
75
|
+
expect(logger.error).not.toHaveBeenCalled();
|
|
76
|
+
|
|
77
|
+
expect(logger.info).toHaveBeenNthCalledWith(
|
|
78
|
+
1,
|
|
79
|
+
expect.objectContaining({ status: 404 }),
|
|
80
|
+
'Client error',
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
metricsClient.expectTagSubset([
|
|
84
|
+
'http_method:get',
|
|
85
|
+
'http_status:404',
|
|
86
|
+
'http_status_family:4xx',
|
|
87
|
+
'route:unspecified',
|
|
88
|
+
]);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('handles returned client error', async () => {
|
|
92
|
+
const message = chance.sentence();
|
|
93
|
+
|
|
94
|
+
middleware.mockImplementation((ctx) => {
|
|
95
|
+
ctx.body = message;
|
|
96
|
+
ctx.status = 400;
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
await agent
|
|
100
|
+
.get('/')
|
|
101
|
+
.expect(400, message)
|
|
102
|
+
.expect('server', /.+/)
|
|
103
|
+
.expect('x-api-version', /.+/);
|
|
104
|
+
|
|
105
|
+
expect(logger.error).not.toHaveBeenCalled();
|
|
106
|
+
|
|
107
|
+
expect(logger.info).toHaveBeenNthCalledWith(
|
|
108
|
+
1,
|
|
109
|
+
expect.objectContaining({ status: 400 }),
|
|
110
|
+
'Client error',
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
metricsClient.expectTagSubset([
|
|
114
|
+
'http_method:get',
|
|
115
|
+
'http_status:400',
|
|
116
|
+
'http_status_family:4xx',
|
|
117
|
+
'route:/',
|
|
118
|
+
]);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('handles client error thrown from context', async () => {
|
|
122
|
+
const message = chance.sentence();
|
|
123
|
+
|
|
124
|
+
middleware.mockImplementation((ctx) => ctx.throw(400, message));
|
|
125
|
+
|
|
126
|
+
await agent
|
|
127
|
+
.get('/')
|
|
128
|
+
.expect(400, message)
|
|
129
|
+
.expect('server', /.+/)
|
|
130
|
+
.expect('x-api-version', /.+/);
|
|
131
|
+
|
|
132
|
+
expect(logger.error).not.toHaveBeenCalled();
|
|
133
|
+
|
|
134
|
+
expect(logger.info).toHaveBeenNthCalledWith(
|
|
135
|
+
1,
|
|
136
|
+
expect.objectContaining({ err: expect.any(Error), status: 400 }),
|
|
137
|
+
'Client error',
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
metricsClient.expectTagSubset([
|
|
141
|
+
'http_method:get',
|
|
142
|
+
'http_status:400',
|
|
143
|
+
'http_status_family:4xx',
|
|
144
|
+
'route:/',
|
|
145
|
+
]);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('handles server error thrown from context', async () => {
|
|
149
|
+
const message = chance.sentence();
|
|
150
|
+
|
|
151
|
+
middleware.mockImplementation((ctx) => ctx.throw(500, message));
|
|
152
|
+
|
|
153
|
+
await agent
|
|
154
|
+
.get('/')
|
|
155
|
+
.expect(500, '')
|
|
156
|
+
.expect('server', /.+/)
|
|
157
|
+
.expect('x-api-version', /.+/);
|
|
158
|
+
|
|
159
|
+
expect(logger.error).toHaveBeenNthCalledWith(
|
|
160
|
+
1,
|
|
161
|
+
expect.objectContaining({ err: expect.any(Error), status: 500 }),
|
|
162
|
+
'Server error',
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
expect(logger.info).not.toHaveBeenCalled();
|
|
166
|
+
|
|
167
|
+
metricsClient.expectTagSubset([
|
|
168
|
+
'http_method:get',
|
|
169
|
+
'http_status:500',
|
|
170
|
+
'http_status_family:5xx',
|
|
171
|
+
'route:/',
|
|
172
|
+
]);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('handles directly-thrown error', async () => {
|
|
176
|
+
const err = Error(chance.sentence());
|
|
177
|
+
|
|
178
|
+
middleware.mockImplementation(() => {
|
|
179
|
+
throw err;
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
await agent
|
|
183
|
+
.get('/')
|
|
184
|
+
.expect(500, '')
|
|
185
|
+
.expect('server', /.+/)
|
|
186
|
+
.expect('x-api-version', /.+/);
|
|
187
|
+
|
|
188
|
+
expect(logger.error).toHaveBeenNthCalledWith(
|
|
189
|
+
1,
|
|
190
|
+
expect.objectContaining({ err, status: 500 }),
|
|
191
|
+
'Server error',
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
expect(logger.info).not.toHaveBeenCalled();
|
|
195
|
+
|
|
196
|
+
metricsClient.expectTagSubset([
|
|
197
|
+
'http_method:get',
|
|
198
|
+
'http_status:500',
|
|
199
|
+
'http_status_family:5xx',
|
|
200
|
+
'route:/',
|
|
201
|
+
]);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('handles null error', async () => {
|
|
205
|
+
middleware.mockImplementation(() => {
|
|
206
|
+
/* eslint-disable-next-line no-throw-literal */
|
|
207
|
+
throw null;
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
await agent
|
|
211
|
+
.get('/')
|
|
212
|
+
.expect(500, '')
|
|
213
|
+
.expect('server', /.+/)
|
|
214
|
+
.expect('x-api-version', /.+/);
|
|
215
|
+
|
|
216
|
+
expect(logger.error).toHaveBeenNthCalledWith(
|
|
217
|
+
1,
|
|
218
|
+
expect.objectContaining({ err: null, status: 500 }),
|
|
219
|
+
'Server error',
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
expect(logger.info).not.toHaveBeenCalled();
|
|
223
|
+
|
|
224
|
+
metricsClient.expectTagSubset([
|
|
225
|
+
'http_method:get',
|
|
226
|
+
'http_status:500',
|
|
227
|
+
'http_status_family:5xx',
|
|
228
|
+
'route:/',
|
|
229
|
+
]);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it('handles string error', async () => {
|
|
233
|
+
const err = chance.sentence();
|
|
234
|
+
|
|
235
|
+
middleware.mockImplementation(() => {
|
|
236
|
+
throw err;
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
await agent
|
|
240
|
+
.get('/')
|
|
241
|
+
.expect(500, '')
|
|
242
|
+
.expect('server', /.+/)
|
|
243
|
+
.expect('x-api-version', /.+/);
|
|
244
|
+
|
|
245
|
+
expect(logger.error).toHaveBeenNthCalledWith(
|
|
246
|
+
1,
|
|
247
|
+
expect.objectContaining({ err, status: 500 }),
|
|
248
|
+
'Server error',
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
expect(logger.info).not.toHaveBeenCalled();
|
|
252
|
+
|
|
253
|
+
metricsClient.expectTagSubset([
|
|
254
|
+
'http_method:get',
|
|
255
|
+
'http_status:500',
|
|
256
|
+
'http_status_family:5xx',
|
|
257
|
+
'route:/',
|
|
258
|
+
]);
|
|
259
|
+
});
|
|
260
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import Koa from 'koa';
|
|
2
|
+
import compose from 'koa-compose';
|
|
3
|
+
import {
|
|
4
|
+
ErrorMiddleware,
|
|
5
|
+
MetricsMiddleware,
|
|
6
|
+
RequestLogging,
|
|
7
|
+
// SecureHeaders,
|
|
8
|
+
VersionMiddleware,
|
|
9
|
+
} from 'seek-koala';
|
|
10
|
+
|
|
11
|
+
import { config } from 'src/config';
|
|
12
|
+
import { contextMiddleware, logger } from 'src/framework/logging';
|
|
13
|
+
import { metricsClient } from 'src/framework/metrics';
|
|
14
|
+
|
|
15
|
+
const metrics = MetricsMiddleware.create(
|
|
16
|
+
metricsClient,
|
|
17
|
+
({ _matchedRoute }) => ({
|
|
18
|
+
route: typeof _matchedRoute === 'string' ? _matchedRoute : 'unspecified',
|
|
19
|
+
}),
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const requestLogging = RequestLogging.createMiddleware((ctx, fields, err) => {
|
|
23
|
+
if (ctx.status < 400 && err === undefined) {
|
|
24
|
+
// Depend on sidecar logging for happy path requests
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return ctx.status < 500
|
|
29
|
+
? logger.info(fields, 'Client error')
|
|
30
|
+
: logger.error(fields, 'Server error');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const version = VersionMiddleware.create({
|
|
34
|
+
name: config.name,
|
|
35
|
+
version: config.version,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export const createApp = <State, Context>(
|
|
39
|
+
...middleware: Koa.Middleware<State, Context>[]
|
|
40
|
+
) =>
|
|
41
|
+
new Koa()
|
|
42
|
+
// TODO: consider using a middleware that adds secure HTTP headers.
|
|
43
|
+
// https://github.com/seek-oss/koala/tree/master/src/secureHeaders
|
|
44
|
+
// https://github.com/venables/koa-helmet
|
|
45
|
+
// .use(SecureHeaders.middleware)
|
|
46
|
+
.use(contextMiddleware)
|
|
47
|
+
.use(requestLogging)
|
|
48
|
+
.use(metrics)
|
|
49
|
+
.use(ErrorMiddleware.handle)
|
|
50
|
+
.use(version)
|
|
51
|
+
.use(compose(middleware));
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { agentFromMiddleware } from 'src/testing/server';
|
|
2
|
+
import {
|
|
3
|
+
IdDescriptionSchema,
|
|
4
|
+
chance,
|
|
5
|
+
mockIdDescription,
|
|
6
|
+
} from 'src/testing/types';
|
|
7
|
+
|
|
8
|
+
import { jsonBodyParser } from './middleware';
|
|
9
|
+
import { validate } from './validation';
|
|
10
|
+
|
|
11
|
+
const agent = agentFromMiddleware(jsonBodyParser, (ctx) => {
|
|
12
|
+
const result = validate({
|
|
13
|
+
ctx,
|
|
14
|
+
input: ctx.request.body,
|
|
15
|
+
schema: IdDescriptionSchema,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
ctx.body = result;
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('validate', () => {
|
|
22
|
+
it('permits valid input', () => {
|
|
23
|
+
const idDescription = mockIdDescription();
|
|
24
|
+
|
|
25
|
+
return agent.post('/').send(idDescription).expect(200, idDescription);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('filters additional properties', () => {
|
|
29
|
+
const idDescription = mockIdDescription();
|
|
30
|
+
|
|
31
|
+
return agent
|
|
32
|
+
.post('/')
|
|
33
|
+
.send({ ...idDescription, hacker: chance.name() })
|
|
34
|
+
.expect(200, idDescription);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('blocks mistyped prop', () => {
|
|
38
|
+
const idDescription = mockIdDescription();
|
|
39
|
+
|
|
40
|
+
return agent
|
|
41
|
+
.post('/')
|
|
42
|
+
.send({ ...idDescription, id: null })
|
|
43
|
+
.expect(422)
|
|
44
|
+
.expect(({ body }) =>
|
|
45
|
+
expect(body).toMatchInlineSnapshot(`
|
|
46
|
+
{
|
|
47
|
+
"invalidFields": {
|
|
48
|
+
"/id": "Expected string, received null",
|
|
49
|
+
},
|
|
50
|
+
"message": "Input validation failed",
|
|
51
|
+
}
|
|
52
|
+
`),
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('blocks missing props', () =>
|
|
57
|
+
agent
|
|
58
|
+
.post('/')
|
|
59
|
+
.send({})
|
|
60
|
+
.expect(422)
|
|
61
|
+
.expect(({ body }) =>
|
|
62
|
+
expect(body).toMatchInlineSnapshot(`
|
|
63
|
+
{
|
|
64
|
+
"invalidFields": {
|
|
65
|
+
"/description": "Required",
|
|
66
|
+
"/id": "Required",
|
|
67
|
+
},
|
|
68
|
+
"message": "Input validation failed",
|
|
69
|
+
}
|
|
70
|
+
`),
|
|
71
|
+
));
|
|
72
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { ErrorMiddleware } from 'seek-koala';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
import { Context } from 'src/types/koa';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Converts a `ZodError` into an `invalidFields` object
|
|
8
|
+
*
|
|
9
|
+
* For example, the `ZodError`:
|
|
10
|
+
*
|
|
11
|
+
* ```json
|
|
12
|
+
* {
|
|
13
|
+
* "issues": [
|
|
14
|
+
* {
|
|
15
|
+
* "code": "invalid_type",
|
|
16
|
+
* "expected": "string",
|
|
17
|
+
* "received": "undefined",
|
|
18
|
+
* "path": ["advertiserId"],
|
|
19
|
+
* "message": "advertiserId is required in the URL"
|
|
20
|
+
* }
|
|
21
|
+
* ],
|
|
22
|
+
* "name": "ZodError"
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* Returns:
|
|
27
|
+
*
|
|
28
|
+
* ```json
|
|
29
|
+
* { "/advertiserId": "advertiserId is required in the URL" }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
const parseInvalidFieldsFromError = ({
|
|
33
|
+
errors,
|
|
34
|
+
}: z.ZodError): Record<string, string> =>
|
|
35
|
+
Object.fromEntries(
|
|
36
|
+
errors.map((err) => [`/${err.path.join('/')}`, err.message]),
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
export const validate = <
|
|
40
|
+
Output,
|
|
41
|
+
Def extends z.ZodTypeDef = z.ZodTypeDef,
|
|
42
|
+
Input = Output,
|
|
43
|
+
>({
|
|
44
|
+
ctx,
|
|
45
|
+
input,
|
|
46
|
+
schema,
|
|
47
|
+
}: {
|
|
48
|
+
ctx: Context;
|
|
49
|
+
input: unknown;
|
|
50
|
+
schema: z.ZodSchema<Output, Def, Input>;
|
|
51
|
+
}): Output => {
|
|
52
|
+
const parseResult = schema.safeParse(input);
|
|
53
|
+
if (parseResult.success === false) {
|
|
54
|
+
return ctx.throw(
|
|
55
|
+
422,
|
|
56
|
+
new ErrorMiddleware.JsonResponse('Input validation failed', {
|
|
57
|
+
message: 'Input validation failed',
|
|
58
|
+
invalidFields: parseInvalidFieldsFromError(parseResult.error),
|
|
59
|
+
}),
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
return parseResult.data;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const validateRequestBody = <
|
|
66
|
+
Output,
|
|
67
|
+
Def extends z.ZodTypeDef = z.ZodTypeDef,
|
|
68
|
+
Input = Output,
|
|
69
|
+
>(
|
|
70
|
+
ctx: Context,
|
|
71
|
+
schema: z.ZodSchema<Output, Def, Input>,
|
|
72
|
+
): Output =>
|
|
73
|
+
validate<Output, Def, Input>({
|
|
74
|
+
ctx,
|
|
75
|
+
input: ctx.request.body as unknown,
|
|
76
|
+
schema,
|
|
77
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import './register';
|
|
2
|
+
|
|
3
|
+
import app from './app';
|
|
4
|
+
import { config } from './config';
|
|
5
|
+
import { logger } from './framework/logging';
|
|
6
|
+
|
|
7
|
+
// This implements a minimal version of `koa-cluster`'s interface
|
|
8
|
+
// If your application is deployed with more than 1 vCPU you can delete this
|
|
9
|
+
// file and use `koa-cluster` to run `lib/app`.
|
|
10
|
+
|
|
11
|
+
const listener = app.listen(config.port, () => {
|
|
12
|
+
const address = listener.address();
|
|
13
|
+
|
|
14
|
+
if (typeof address === 'object' && address) {
|
|
15
|
+
logger.debug(`listening on port ${address.port}`);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// Gantry ALB default idle timeout is 30 seconds
|
|
20
|
+
// https://nodejs.org/docs/latest-v18.x/api/http.html#serverkeepalivetimeout
|
|
21
|
+
// Node default is 5 seconds
|
|
22
|
+
// https://docs.aws.amazon.com/elasticloadbalancing/latest/application/application-load-balancers.html#connection-idle-timeout
|
|
23
|
+
// AWS recommends setting an application timeout larger than the load balancer
|
|
24
|
+
listener.keepAliveTimeout = 31000;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'skuba-dive/register';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { randomUUID } from 'crypto';
|
|
2
|
+
|
|
3
|
+
import { Job, JobInput } from 'src/types/jobs';
|
|
4
|
+
|
|
5
|
+
const jobStore: Record<string, Job> = {};
|
|
6
|
+
|
|
7
|
+
export const createJob = (jobInput: JobInput): Promise<Job> => {
|
|
8
|
+
const id = randomUUID();
|
|
9
|
+
|
|
10
|
+
const job = { ...jobInput, id };
|
|
11
|
+
|
|
12
|
+
jobStore[id] = job;
|
|
13
|
+
|
|
14
|
+
return Promise.resolve(job);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const readJobs = (): Promise<Job[]> => {
|
|
18
|
+
const jobs = Object.values(jobStore);
|
|
19
|
+
|
|
20
|
+
return Promise.resolve(jobs);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Tests that we have access to read from and write to our storage.
|
|
25
|
+
*/
|
|
26
|
+
export const smokeTestJobStorage = async (): Promise<void> => {
|
|
27
|
+
await Promise.resolve();
|
|
28
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as logging from 'src/framework/logging';
|
|
2
|
+
|
|
3
|
+
export const logger = {
|
|
4
|
+
error: jest.fn(),
|
|
5
|
+
info: jest.fn(),
|
|
6
|
+
|
|
7
|
+
clear: () => {
|
|
8
|
+
logger.error.mockClear();
|
|
9
|
+
logger.info.mockClear();
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
spy: () => {
|
|
13
|
+
jest.spyOn(logging.logger, 'error').mockImplementation(logger.error);
|
|
14
|
+
jest.spyOn(logging.logger, 'info').mockImplementation(logger.info);
|
|
15
|
+
},
|
|
16
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as metrics from 'src/framework/metrics';
|
|
2
|
+
|
|
3
|
+
function assertDefined<T>(value: T | undefined): asserts value is T {
|
|
4
|
+
expect(value).toBeDefined();
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export const metricsClient = {
|
|
8
|
+
clear: () => (metrics.metricsClient.mockBuffer = []),
|
|
9
|
+
|
|
10
|
+
expectTagSubset: (subset: string[], index: number = 0) => {
|
|
11
|
+
const tags = metricsClient.tags(index);
|
|
12
|
+
|
|
13
|
+
subset.forEach((tag) => expect(tags).toContain(tag));
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
tags: (index: number = 0) => {
|
|
17
|
+
assertDefined(metrics.metricsClient.mockBuffer);
|
|
18
|
+
|
|
19
|
+
const line = metrics.metricsClient.mockBuffer[index];
|
|
20
|
+
|
|
21
|
+
assertDefined(line);
|
|
22
|
+
|
|
23
|
+
const [, tagString] = line.split('#', 2);
|
|
24
|
+
|
|
25
|
+
assertDefined(tagString);
|
|
26
|
+
|
|
27
|
+
return tagString.split(',');
|
|
28
|
+
},
|
|
29
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import Router from '@koa/router';
|
|
2
|
+
import Koa from 'koa';
|
|
3
|
+
import request from 'supertest';
|
|
4
|
+
|
|
5
|
+
import { createApp } from 'src/framework/server';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Create a new SuperTest agent from a Koa application.
|
|
9
|
+
*/
|
|
10
|
+
export const agentFromApp = <State, Context>(app: Koa<State, Context>) =>
|
|
11
|
+
request.agent(app.callback());
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Create a new SuperTest agent from a set of Koa middleware.
|
|
15
|
+
*/
|
|
16
|
+
export const agentFromMiddleware = <State, Context>(
|
|
17
|
+
...middleware: Koa.Middleware<State, Context>[]
|
|
18
|
+
) => {
|
|
19
|
+
const app = createApp(...middleware);
|
|
20
|
+
|
|
21
|
+
return agentFromApp(app);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Create a new SuperTest agent from a Koa router.
|
|
26
|
+
*/
|
|
27
|
+
export const agentFromRouter = (router: Router) => {
|
|
28
|
+
const app = createApp(router.routes(), router.allowedMethods());
|
|
29
|
+
|
|
30
|
+
return agentFromApp(app);
|
|
31
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Chance } from 'chance';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
import { JobInput } from 'src/types/jobs';
|
|
5
|
+
|
|
6
|
+
export type IdDescription = z.infer<typeof IdDescriptionSchema>;
|
|
7
|
+
|
|
8
|
+
export const IdDescriptionSchema = z.object({
|
|
9
|
+
id: z.string(),
|
|
10
|
+
description: z.string(),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export const chance = new Chance();
|
|
14
|
+
|
|
15
|
+
export const mockIdDescription = (): IdDescription => ({
|
|
16
|
+
id: chance.guid({ version: 4 }),
|
|
17
|
+
description: chance.sentence(),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export const mockJobInput = (): JobInput => ({
|
|
21
|
+
hirer: {
|
|
22
|
+
id: chance.guid({ version: 4 }),
|
|
23
|
+
},
|
|
24
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenTelemetry tracing initialisation. This is a standalone TS/JS module that is not
|
|
3
|
+
* referenced by application source code directly. It is required at runtime using the
|
|
4
|
+
* node command's `--require` argument, see Dockerfile for details.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { propagation } from '@opentelemetry/api';
|
|
8
|
+
import { CompositePropagator } from '@opentelemetry/core';
|
|
9
|
+
import { CollectorTraceExporter } from '@opentelemetry/exporter-collector-grpc';
|
|
10
|
+
import { AwsInstrumentation } from '@opentelemetry/instrumentation-aws-sdk';
|
|
11
|
+
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
|
|
12
|
+
import { B3InjectEncoding, B3Propagator } from '@opentelemetry/propagator-b3';
|
|
13
|
+
import { NodeSDK } from '@opentelemetry/sdk-node';
|
|
14
|
+
|
|
15
|
+
const app = 'opentelemetry';
|
|
16
|
+
const log = (level: string, msg: string, extra = {}) => {
|
|
17
|
+
const toLog = { msg, level, app, time: new Date().toISOString(), ...extra };
|
|
18
|
+
console.log(JSON.stringify(toLog)); // eslint-disable-line no-console
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const main = () => {
|
|
22
|
+
// Use B3 propagation to ensure proper propagation between systems that use
|
|
23
|
+
// OpenTelemetry and native Datadog APM, such as Istio/Envoy.
|
|
24
|
+
propagation.setGlobalPropagator(
|
|
25
|
+
new CompositePropagator({
|
|
26
|
+
propagators: [
|
|
27
|
+
new B3Propagator(),
|
|
28
|
+
new B3Propagator({ injectEncoding: B3InjectEncoding.MULTI_HEADER }),
|
|
29
|
+
],
|
|
30
|
+
}),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const sdk = new NodeSDK({
|
|
34
|
+
traceExporter: new CollectorTraceExporter(),
|
|
35
|
+
autoDetectResources: false,
|
|
36
|
+
instrumentations: [new HttpInstrumentation(), new AwsInstrumentation()],
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
sdk
|
|
40
|
+
.start()
|
|
41
|
+
.then(() => log('info', 'OpenTelemetry initialised'))
|
|
42
|
+
.catch((err: Error) =>
|
|
43
|
+
log('error', 'OpenTelemetry not initialised', { err }),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
process.on('SIGTERM', () => {
|
|
47
|
+
sdk
|
|
48
|
+
.shutdown()
|
|
49
|
+
.then(() => log('info', 'OpenTelemetry successfully terminated'))
|
|
50
|
+
.catch((err: Error) =>
|
|
51
|
+
log('error', 'OpenTelemetry failed to terminate', { err }),
|
|
52
|
+
)
|
|
53
|
+
.finally(() => process.exit(0)); // eslint-disable-line no-process-exit
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
if (process.env.OPENTELEMETRY_ENABLED === 'true') {
|
|
58
|
+
main();
|
|
59
|
+
} else {
|
|
60
|
+
log('info', 'OpenTelemetry not enabled');
|
|
61
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
export interface Job {
|
|
4
|
+
id: string;
|
|
5
|
+
|
|
6
|
+
hirer: {
|
|
7
|
+
id: string;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type JobInput = z.infer<typeof JobInputSchema>;
|
|
12
|
+
|
|
13
|
+
export const JobInputSchema = z.object({
|
|
14
|
+
hirer: z.object({
|
|
15
|
+
id: z.string(),
|
|
16
|
+
}),
|
|
17
|
+
});
|