@openstax/ts-utils 1.2.8 → 1.3.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.
Files changed (134) hide show
  1. package/dist/cjs/assertions.d.ts +75 -0
  2. package/dist/cjs/assertions.js +74 -29
  3. package/dist/cjs/aws/ssmService.d.ts +3 -0
  4. package/dist/cjs/aws/ssmService.js +3 -0
  5. package/dist/cjs/config/awsParameterConfig.d.ts +8 -0
  6. package/dist/cjs/config/awsParameterConfig.js +8 -0
  7. package/dist/cjs/config/envConfig.d.ts +21 -0
  8. package/dist/cjs/config/envConfig.js +20 -14
  9. package/dist/cjs/config/index.d.ts +28 -0
  10. package/dist/cjs/config/index.js +3 -6
  11. package/dist/cjs/config/lambdaParameterConfig.d.ts +10 -0
  12. package/dist/cjs/config/lambdaParameterConfig.js +10 -2
  13. package/dist/cjs/config/replaceConfig.d.ts +10 -0
  14. package/dist/cjs/config/replaceConfig.js +10 -0
  15. package/dist/cjs/config/resolveConfigValue.d.ts +3 -0
  16. package/dist/cjs/config/resolveConfigValue.js +2 -2
  17. package/dist/cjs/errors.d.ts +27 -0
  18. package/dist/cjs/errors.js +29 -2
  19. package/dist/cjs/guards.d.ts +24 -0
  20. package/dist/cjs/guards.js +18 -19
  21. package/dist/cjs/middleware/apiErrorHandler.d.ts +8 -0
  22. package/dist/cjs/middleware/apiErrorHandler.js +8 -0
  23. package/dist/cjs/middleware/apiSlowResponseMiddleware.d.ts +12 -0
  24. package/dist/cjs/middleware/apiSlowResponseMiddleware.js +12 -0
  25. package/dist/cjs/middleware/lambdaCorsResponseMiddleware.d.ts +11 -1
  26. package/dist/cjs/middleware/lambdaCorsResponseMiddleware.js +11 -1
  27. package/dist/cjs/middleware/throwNotFoundMiddleware.d.ts +3 -0
  28. package/dist/cjs/middleware/throwNotFoundMiddleware.js +3 -0
  29. package/dist/cjs/middleware.d.ts +38 -0
  30. package/dist/cjs/middleware.js +26 -16
  31. package/dist/cjs/misc/hashValue.d.ts +5 -0
  32. package/dist/cjs/misc/hashValue.js +3 -4
  33. package/dist/cjs/misc/helpers.d.ts +94 -0
  34. package/dist/cjs/misc/helpers.js +52 -14
  35. package/dist/cjs/misc/merge.d.ts +18 -0
  36. package/dist/cjs/misc/merge.js +10 -3
  37. package/dist/cjs/misc/partitionSequence.d.ts +31 -0
  38. package/dist/cjs/misc/partitionSequence.js +1 -1
  39. package/dist/cjs/pagination.d.ts +28 -0
  40. package/dist/cjs/pagination.js +1 -1
  41. package/dist/cjs/routing/helpers.d.ts +45 -0
  42. package/dist/cjs/routing/helpers.js +40 -22
  43. package/dist/cjs/routing/index.d.ts +169 -0
  44. package/dist/cjs/routing/index.js +127 -45
  45. package/dist/cjs/services/apiGateway/index.d.ts +1 -0
  46. package/dist/cjs/services/apiGateway/index.js +2 -0
  47. package/dist/cjs/services/authProvider/index.d.ts +2 -1
  48. package/dist/cjs/services/authProvider/utils/decryptAndVerify.d.ts +9 -0
  49. package/dist/cjs/services/authProvider/utils/decryptAndVerify.js +9 -0
  50. package/dist/cjs/services/logger/console.d.ts +3 -0
  51. package/dist/cjs/services/logger/console.js +3 -0
  52. package/dist/cjs/services/logger/index.d.ts +25 -0
  53. package/dist/cjs/services/logger/index.js +11 -0
  54. package/dist/cjs/services/lrsGateway/attempt-utils.d.ts +7 -10
  55. package/dist/cjs/services/lrsGateway/attempt-utils.js +19 -40
  56. package/dist/cjs/tsconfig.without-specs.cjs.tsbuildinfo +1 -1
  57. package/dist/cjs/types.d.ts +21 -0
  58. package/dist/esm/assertions.d.ts +75 -0
  59. package/dist/esm/assertions.js +74 -29
  60. package/dist/esm/aws/ssmService.d.ts +3 -0
  61. package/dist/esm/aws/ssmService.js +3 -0
  62. package/dist/esm/config/awsParameterConfig.d.ts +8 -0
  63. package/dist/esm/config/awsParameterConfig.js +8 -0
  64. package/dist/esm/config/envConfig.d.ts +21 -0
  65. package/dist/esm/config/envConfig.js +20 -14
  66. package/dist/esm/config/index.d.ts +28 -0
  67. package/dist/esm/config/index.js +3 -6
  68. package/dist/esm/config/lambdaParameterConfig.d.ts +10 -0
  69. package/dist/esm/config/lambdaParameterConfig.js +10 -2
  70. package/dist/esm/config/replaceConfig.d.ts +10 -0
  71. package/dist/esm/config/replaceConfig.js +10 -0
  72. package/dist/esm/config/resolveConfigValue.d.ts +3 -0
  73. package/dist/esm/config/resolveConfigValue.js +2 -2
  74. package/dist/esm/errors.d.ts +27 -0
  75. package/dist/esm/errors.js +27 -0
  76. package/dist/esm/guards.d.ts +24 -0
  77. package/dist/esm/guards.js +18 -19
  78. package/dist/esm/middleware/apiErrorHandler.d.ts +8 -0
  79. package/dist/esm/middleware/apiErrorHandler.js +8 -0
  80. package/dist/esm/middleware/apiSlowResponseMiddleware.d.ts +12 -0
  81. package/dist/esm/middleware/apiSlowResponseMiddleware.js +12 -0
  82. package/dist/esm/middleware/lambdaCorsResponseMiddleware.d.ts +11 -1
  83. package/dist/esm/middleware/lambdaCorsResponseMiddleware.js +11 -1
  84. package/dist/esm/middleware/throwNotFoundMiddleware.d.ts +3 -0
  85. package/dist/esm/middleware/throwNotFoundMiddleware.js +3 -0
  86. package/dist/esm/middleware.d.ts +38 -0
  87. package/dist/esm/middleware.js +26 -16
  88. package/dist/esm/misc/hashValue.d.ts +5 -0
  89. package/dist/esm/misc/hashValue.js +3 -4
  90. package/dist/esm/misc/helpers.d.ts +94 -0
  91. package/dist/esm/misc/helpers.js +48 -10
  92. package/dist/esm/misc/merge.d.ts +18 -0
  93. package/dist/esm/misc/merge.js +10 -3
  94. package/dist/esm/misc/partitionSequence.d.ts +31 -0
  95. package/dist/esm/misc/partitionSequence.js +1 -1
  96. package/dist/esm/pagination.d.ts +28 -0
  97. package/dist/esm/pagination.js +1 -1
  98. package/dist/esm/routing/helpers.d.ts +45 -0
  99. package/dist/esm/routing/helpers.js +40 -22
  100. package/dist/esm/routing/index.d.ts +169 -0
  101. package/dist/esm/routing/index.js +127 -45
  102. package/dist/esm/services/apiGateway/index.d.ts +1 -0
  103. package/dist/esm/services/apiGateway/index.js +2 -0
  104. package/dist/esm/services/authProvider/index.d.ts +2 -1
  105. package/dist/esm/services/authProvider/utils/decryptAndVerify.d.ts +9 -0
  106. package/dist/esm/services/authProvider/utils/decryptAndVerify.js +9 -0
  107. package/dist/esm/services/logger/console.d.ts +3 -0
  108. package/dist/esm/services/logger/console.js +3 -0
  109. package/dist/esm/services/logger/index.d.ts +25 -0
  110. package/dist/esm/services/logger/index.js +11 -0
  111. package/dist/esm/services/lrsGateway/attempt-utils.d.ts +7 -10
  112. package/dist/esm/services/lrsGateway/attempt-utils.js +16 -35
  113. package/dist/esm/tsconfig.without-specs.esm.tsbuildinfo +1 -1
  114. package/dist/esm/types.d.ts +21 -0
  115. package/package.json +3 -2
  116. package/script/bin/copy-from-template.bash +32 -0
  117. package/script/bin/delete-stack.bash +22 -0
  118. package/script/bin/deploy.bash +41 -0
  119. package/script/bin/destroy-deployment.bash +60 -0
  120. package/script/bin/empty-bucket.bash +28 -0
  121. package/script/bin/get-arg.bash +10 -0
  122. package/script/bin/get-deployed-environments.bash +9 -0
  123. package/script/bin/get-env-param.bash +23 -0
  124. package/script/bin/get-kwarg.bash +10 -0
  125. package/script/bin/get-stack-param.bash +6 -0
  126. package/script/bin/has-flag.bash +10 -0
  127. package/script/bin/init-constants-script.bash +20 -0
  128. package/script/bin/init-params-script.bash +118 -0
  129. package/script/bin/stack-exists.bash +5 -0
  130. package/script/bin/upload-pager-duty-endpoints.bash +44 -0
  131. package/script/bin/upload-params.bash +59 -0
  132. package/script/bin/which.bash +14 -0
  133. package/script/bin-entry.bash +33 -0
  134. package/script/build.bash +21 -0
@@ -1,6 +1,27 @@
1
+ /**
2
+ * Returns the literal type `'yes'` if the first generic tuple array is a prefix of the second,
3
+ * the `'no'` literal type otherwise. Can be used in conditional types, e.g.
4
+ *
5
+ * `type WillBeString = TupleExtends<[1,2], [1,2,3]> extends 'yes' ? string : number;`
6
+ *
7
+ * There may be a better way to do this; `T1 extends T2` doesn't work
8
+ */
1
9
  export declare type TupleExtends<T1, T2> = T1 extends [infer T1Head, ...infer T1Tail] ? T2 extends [infer T2Head, ...infer T2Tail] ? T1Head extends T2Head ? TupleExtends<T1Tail, T2Tail> extends 'yes' ? 'yes' : 'no' : 'no' : T2 extends [] ? 'yes' : 'no' : T1 extends [] ? T2 extends [] ? 'yes' : 'no' : 'no';
10
+ /**
11
+ * If `R` is `Promise<I>`, returns `I`, otherwise returns `R`
12
+ * @deprecated use TypeScript builtin Awaited instead:
13
+ * @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-5.html#the-awaited-type-and-promise-improvements
14
+ */
2
15
  export declare type UnwrapPromise<R> = R extends Promise<infer I> ? I : R;
16
+ /**
17
+ * turns `thing | thing2` into `thing & thing2`
18
+ * @see https://stackoverflow.com/a/50375286/14809536
19
+ */
3
20
  export declare type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
21
+ /**
22
+ * make certain fields required
23
+ * @see https://stackoverflow.com/a/69328045/14809536
24
+ */
4
25
  export declare type WithRequired<T, K extends keyof T> = T & {
5
26
  [P in K]-?: T[P];
6
27
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@openstax/ts-utils",
3
3
  "sideEffects": false,
4
- "version": "1.2.8",
4
+ "version": "1.3.0",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
7
  "exports": {
@@ -27,7 +27,8 @@
27
27
  }
28
28
  },
29
29
  "files": [
30
- "dist"
30
+ "dist",
31
+ "script"
31
32
  ],
32
33
  "typesVersions": {
33
34
  "*": {
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env bash
2
+ # spell-checker: ignore pipefail syncignore lastsync nowarn mktemp
3
+ set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
4
+
5
+ project_dir=$(pwd)
6
+
7
+ temp_dir="$(dirname "$(mktemp -u)")/service-template"
8
+ patch_file=$(mktemp -t tst-patch.XXX)
9
+
10
+ if [ -d "$temp_dir" ]; then
11
+ cd "$temp_dir"
12
+ git pull
13
+ else
14
+ git clone git@github.com:openstax/typescript-service-template.git "$temp_dir"
15
+ cd "$temp_dir"
16
+ fi
17
+
18
+ read -d '\n' -r -a sync_ignore <<< "$(awk '{print ":\!*" $0}' "$project_dir/.syncignore")" || true
19
+
20
+ sync_from=$(git hash-object -t tree /dev/null)
21
+ if [ -f "$project_dir/.lastsync" ]; then
22
+ sync_from=$(< "$project_dir/.lastsync")
23
+ fi
24
+
25
+ git rev-parse HEAD > "$project_dir/.lastsync"
26
+ git --no-pager diff --binary "$sync_from" "${sync_ignore[@]}" > "$patch_file"
27
+
28
+ cd "$project_dir"
29
+
30
+ git apply --reject --whitespace=nowarn "$patch_file" || true
31
+
32
+ echo "$project_dir"
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env bash
2
+ # spell-checker: ignore pipefail
3
+ set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
4
+
5
+ if [ -z "${AWS_DEFAULT_REGION:-}" ]; then echo "AWS_DEFAULT_REGION must be set" > /dev/stderr; exit 1; fi
6
+
7
+ name=$1
8
+ region=$2
9
+
10
+ printf "\nchecking %s stack..." "$name"
11
+ if AWS_DEFAULT_REGION="$region" yarn -s ts-utils stack-exists "$name"; then
12
+ printf " deleting it"
13
+ AWS_DEFAULT_REGION="$region" aws cloudformation delete-stack --region "$region" --stack-name "$name"
14
+
15
+ while AWS_DEFAULT_REGION="$region" yarn -s ts-utils stack-exists "$name"; do
16
+ printf "."
17
+ sleep 5
18
+ done
19
+ echo
20
+ else
21
+ echo "stack not found."
22
+ fi
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env bash
2
+ # spell-checker: ignore pipefail
3
+ set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
4
+
5
+ source $(yarn -s ts-utils which init-constants-script)
6
+
7
+ if [ -z "${APPLICATION:-}" ]; then echo "APPLICATION must be set" > /dev/stderr; exit 1; fi
8
+ if [ -z "${OWNER:-}" ]; then echo "OWNER must be set" > /dev/stderr; exit 1; fi
9
+ if [ -z "${PROJECT:-}" ]; then echo "PROJECT must be set" > /dev/stderr; exit 1; fi
10
+ if [ -z "${AWS_DEFAULT_REGION:-}" ]; then echo "AWS_DEFAULT_REGION must be set" > /dev/stderr; exit 1; fi
11
+
12
+ if [ "$#" -lt 1 ]; then
13
+ cat <<HEREDOC
14
+
15
+ Usage: yarn -s ts-utils deploy <environment>
16
+
17
+ Deploys the given $APPLICATION environment
18
+
19
+ HEREDOC
20
+
21
+ exit 1
22
+ fi
23
+
24
+ ENVIRONMENT=$1
25
+ export ENVIRONMENT;
26
+
27
+ # this outputs the account alias, eg "openstax" or "openstax-dev-sandbox"
28
+ AWS_ACCOUNT=$(aws iam list-account-aliases --output text --query 'AccountAliases[0]')
29
+ export AWS_ACCOUNT;
30
+
31
+ if [ -z "$AWS_ACCOUNT" ]; then
32
+ echo "authorized. aws account not set, make sure you're logged in" > /dev/stderr
33
+ exit 1
34
+ fi
35
+
36
+ if [ ! -f "./deploy/deploy.bash" ]; then
37
+ echo "could not find project deployment script at ./deploy/deploy.bash" > /dev/stderr;
38
+ exit 1
39
+ fi;
40
+
41
+ ./deploy/deploy.bash
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env bash
2
+ # spell-checker: ignore pipefail kwarg
3
+ set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
4
+
5
+ source $(yarn -s ts-utils which init-constants-script)
6
+
7
+ if [ -z "${APPLICATION:-}" ]; then echo "APPLICATION must be set" > /dev/stderr; exit 1; fi
8
+ if [ -z "${OWNER:-}" ]; then echo "OWNER must be set" > /dev/stderr; exit 1; fi
9
+ if [ -z "${PROJECT:-}" ]; then echo "PROJECT must be set" > /dev/stderr; exit 1; fi
10
+ if [ -z "${AWS_DEFAULT_REGION:-}" ]; then echo "AWS_DEFAULT_REGION must be set" > /dev/stderr; exit 1; fi
11
+
12
+ function print_usage_and_exit() {
13
+ cat <<HEREDOC
14
+
15
+ Usage: yarn -s ts-utils destroy-deployment <environment> [options]
16
+
17
+ Destroys the given $APPLICATION environment
18
+
19
+ Options:
20
+ -y - skips confirmation prompts - default: don't skip
21
+
22
+ HEREDOC
23
+
24
+ exit 1
25
+ }
26
+
27
+ if [ "$#" -lt 1 ]; then
28
+ print_usage_and_exit
29
+ fi
30
+
31
+ ENVIRONMENT=$(yarn -s ts-utils get-arg 0 "$@")
32
+ export ENVIRONMENT;
33
+
34
+ YES=$(yarn -s ts-utils get-kwarg y "$@")
35
+ export YES
36
+
37
+ if [ -z "$YES" ]; then
38
+ printf "This will destroy the %s %s environment. Proceed? [y/N]: " "$APPLICATION" "$ENVIRONMENT"
39
+ read -r do_it
40
+
41
+ if [ "$do_it" != "y" ]; then
42
+ exit 1
43
+ fi
44
+ fi
45
+
46
+ # this outputs the account alias, eg "openstax" or "openstax-dev-sandbox"
47
+ AWS_ACCOUNT=$(aws iam list-account-aliases --output text --query 'AccountAliases[0]')
48
+ export AWS_ACCOUNT;
49
+
50
+ if [ -z "$AWS_ACCOUNT" ]; then
51
+ echo "authorized. aws account not set, make sure you're logged in" > /dev/stderr
52
+ exit 1
53
+ fi
54
+
55
+ if [ ! -f "./deploy/destroy-deployment.bash" ]; then
56
+ echo "could not find project destroy deployment script at ./deploy/destroy-deployment.bash" > /dev/stderr;
57
+ exit 1
58
+ fi;
59
+
60
+ ./deploy/destroy-deployment.bash
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env bash
2
+ # spell-checker: ignore pipefail
3
+ set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
4
+
5
+ cliVersion=$(aws --version)
6
+ if [[ "$cliVersion" == aws-cli/2* ]]; then
7
+ pager=--no-cli-pager
8
+ else
9
+ pager=
10
+ fi
11
+
12
+ bucketName=$1
13
+ # Deleting versioned buckets is harder than non-versioned ones
14
+
15
+ versions=$(aws s3api list-object-versions \
16
+ --bucket "$bucketName" \
17
+ --output json \
18
+ --query '{Objects: Versions[].{Key:Key,VersionId:VersionId}}' \
19
+ "$pager")
20
+
21
+ versionsWithQuietFlag="${versions:0:$((${#versions}-1))}, \"Quiet\": true }"
22
+
23
+ if [[ ${versions} =~ Objects\":\ null ]]; then
24
+ echo "$bucketName" is empty.
25
+ else
26
+ echo "Deleting files in $bucketName."
27
+ aws s3api delete-objects --bucket "$bucketName" --delete "$versionsWithQuietFlag" "$pager"
28
+ fi
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env bash
2
+ # spell-checker: ignore pipefail yargs
3
+ set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
4
+
5
+ target=$1
6
+ shift
7
+ args=("$@")
8
+
9
+ # https://stackoverflow.com/a/61551944/14809536
10
+ node -e "console.log(require('yargs').argv['_']['$target'] || '')" -- yargs "${args[@]+"${args[@]}"}"
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env bash
2
+ # spell-checker: ignore pipefail
3
+ set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
4
+
5
+ source $(yarn -s ts-utils which init-constants-script)
6
+
7
+ if [ -z "${AWS_DEFAULT_REGION:-}" ]; then echo "AWS_DEFAULT_REGION must be set" > /dev/stderr; exit 1; fi
8
+
9
+ aws cloudformation describe-stacks --query "Stacks[?Tags[?Key == 'Project' && Value == '$PROJECT'] && Tags[?Key == 'Application' && Value == '$APPLICATION'] && Tags[?Key == 'Environment' && Value != 'shared']].[Tags[?Key=='Environment'].Value]" --output text
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env bash
2
+ # spell-checker: ignore pipefail
3
+ set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
4
+
5
+ source $(yarn -s ts-utils which init-constants-script)
6
+ source $(yarn -s ts-utils which init-params-script)
7
+
8
+ environment=$(yarn -s ts-utils get-arg 0 "$@")
9
+ param=$(yarn -s ts-utils get-arg 1 "$@")
10
+
11
+ if [ -z "$environment" ] || [ -z "$param" ]; then
12
+ cat <<HEREDOC
13
+ Usage: $(basename ${BASH_SOURCE[0]}) <environment> <parameter name>
14
+
15
+ Shows secret value from AWS parameter store
16
+ HEREDOC
17
+
18
+ exit 1
19
+ fi
20
+
21
+ name=$(get_param_name)
22
+
23
+ get_parameter
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env bash
2
+ # spell-checker: ignore pipefail yargs
3
+ set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
4
+
5
+ target=$1
6
+ shift
7
+ args=("$@")
8
+
9
+ # https://stackoverflow.com/a/61551944/14809536
10
+ node -e "console.log(require('yargs').argv['$target'] || '')" -- yargs "${args[@]+"${args[@]}"}"
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ # spell-checker: ignore pipefail
3
+ set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
4
+
5
+ aws cloudformation describe-stacks --stack-name "$1" --output json | \
6
+ jq -r --arg key "$2" '(.Stacks[0].Outputs // [])[]|select(.OutputKey == $key).OutputValue'
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env bash
2
+ # spell-checker: ignore pipefail yargs
3
+ set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
4
+
5
+ target=$1
6
+ shift
7
+ args=("$@")
8
+
9
+ # https://stackoverflow.com/a/61551944/14809536
10
+ node -e "if (!require('yargs').argv['$target']) { process.exit(1) }" -- yargs "${args[@]+"${args[@]}"}"
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env bash
2
+ # spell-checker: ignore pipefail
3
+ set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
4
+
5
+ # https://stackoverflow.com/a/28776166
6
+ ([[ -n "${ZSH_EVAL_CONTEXT:-}" && "$ZSH_EVAL_CONTEXT" =~ :file$ ]] ||
7
+ [[ -n "$BASH_VERSION" ]] && (return 0 2>/dev/null)) && sourced=true || sourced=false
8
+
9
+ if [ "$sourced" == "false" ]; then
10
+ echo "env files must be sourced" > /dev/stderr
11
+ exit 1
12
+ fi;
13
+
14
+ # yarn seems to naturally run things from the project root, so this is just a safety check
15
+ if [ ! -f "./deploy/constants.env" ]; then
16
+ echo "This command must be run from the project root directory" > /dev/stderr;
17
+ exit 1
18
+ fi;
19
+
20
+ source "./deploy/constants.env"
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env bash
2
+ # spell-checker: ignore pipefail kwarg urlparam
3
+ set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
4
+
5
+ # https://stackoverflow.com/a/28776166
6
+ ([[ -n "${ZSH_EVAL_CONTEXT:-}" && "$ZSH_EVAL_CONTEXT" =~ :file$ ]] ||
7
+ [[ -n "$BASH_VERSION" ]] && (return 0 2>/dev/null)) && sourced=true || sourced=false
8
+
9
+ if [ "$sourced" == "false" ]; then
10
+ echo "env files must be sourced" > /dev/stderr
11
+ exit 1
12
+ fi;
13
+
14
+ # note - usually you wouldn't use exit from a sourced script, but this is never sourced
15
+ # into an interactive shell, only as a script helper, so we want it to exit the script
16
+ if [ -z "${APPLICATION:-}" ]; then echo "APPLICATION must be set" > /dev/stderr; exit 1; fi
17
+ if [ -z "${OWNER:-}" ]; then echo "OWNER must be set" > /dev/stderr; exit 1; fi
18
+ if [ -z "${PROJECT:-}" ]; then echo "PROJECT must be set" > /dev/stderr; exit 1; fi
19
+
20
+ region=$(yarn -s ts-utils get-kwarg r "$@")
21
+ region=${region:-us-east-1}
22
+
23
+ # Prevent bad behavior when trying to upload URL params on aws cli v1
24
+ aws_version=$(aws --version)
25
+ if [ -z "${aws_version##aws-cli/1.*}" ]; then
26
+ # true is the default value for aws cli v1
27
+ original_cli_follow_urlparam=$(aws configure get cli_follow_urlparam || echo 'true')
28
+
29
+ function restore_cli_follow_urlparam() {
30
+ aws configure set cli_follow_urlparam "$original_cli_follow_urlparam"
31
+ }
32
+
33
+ # Needed to upload URLs as secret values. Explanation: https://github.com/aws/aws-cli/issues/2507
34
+ aws configure set cli_follow_urlparam false
35
+
36
+ trap restore_cli_follow_urlparam EXIT
37
+ fi
38
+
39
+ function get_param_name() {
40
+ echo "/$APPLICATION/$environment/api/$param"
41
+ }
42
+
43
+ function get_value() {
44
+ printf "Enter new value for \"$name\" (leave blank to skip): "
45
+ read -r value
46
+ }
47
+
48
+ function get_parameter() {
49
+ aws ssm get-parameter --region "$region" --name "$name" --with-decryption \
50
+ --query Parameter.Value --output text 2>&1
51
+ }
52
+
53
+ function upload_parameter() {
54
+ set +e
55
+ previous_value=$(get_parameter)
56
+ get_parameter_failed=$?
57
+ set -e
58
+
59
+ if [ "$get_parameter_failed" -eq 0 ]; then
60
+ echo "Parameter \"$name\" already exists"
61
+
62
+ if [ -n "${interactive:-}" ]; then
63
+ echo "Current value: \"$previous_value\""
64
+
65
+ get_value
66
+
67
+ if [ -z "$value" ]; then
68
+ echo "Skipping parameter \"$name\" (previous value kept)"
69
+
70
+ return
71
+ fi
72
+ # The parameter store (or maybe the upload command) removes trailing newlines
73
+ # Maybe relevant when uploading public/private key certificates
74
+ elif [ "$value" = "$previous_value" ] || [ "$value" = "$previous_value"$'\n' ]; then
75
+ echo "Skipping parameter \"$name\" as the new and previous values match"
76
+
77
+ return
78
+ else
79
+ echo "New and previous values for parameter \"$param\" differ"
80
+
81
+ if [ -z "$overwrite" ]; then
82
+ echo "Skipping parameter \"$name\" as the -o option was not set (previous value kept)"
83
+
84
+ return
85
+ fi
86
+ fi
87
+
88
+ if [ -n "$value" ]; then
89
+ echo "Overwriting parameter \"$name\" with new value"
90
+
91
+ aws ssm put-parameter --region "$region" --type SecureString \
92
+ --name "$name" --value "$value" --overwrite
93
+ else
94
+ echo "Skipping parameter \"$name\" (previous value kept)"
95
+ fi
96
+ elif [[ -n "${previous_value##*ParameterNotFound*}" ]]; then
97
+ # Error is NOT ParameterNotFound
98
+ printf "%s\n\n" "$previous_value"
99
+ exit 1
100
+ else
101
+ # Error is ParameterNotFound
102
+ if [ -n "${interactive:-}" ]; then
103
+ get_value
104
+
105
+ if [ -z "$value" ]; then
106
+ echo "Skipping parameter \"$name\" (not uploaded)"
107
+
108
+ return
109
+ fi
110
+ fi
111
+
112
+ echo "Uploading new parameter \"$name\""
113
+
114
+ aws ssm put-parameter --region "$region" --type SecureString --name "$name" --value "$value" \
115
+ --tags "Key=Project,Value=$PROJECT" "Key=Application,Value=$APPLICATION" \
116
+ 'Key=Environment,Value=shared' "Key=Owner,Value=$OWNER"
117
+ fi
118
+ }
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env bash
2
+ # spell-checker: ignore pipefail
3
+ set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
4
+
5
+ aws cloudformation describe-stacks --stack-name "$1" > /dev/null 2>&1
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env bash
2
+ # spell-checker: ignore pipefail kwarg
3
+ set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
4
+
5
+ source $(yarn -s ts-utils which init-constants-script)
6
+ source $(yarn -s ts-utils which init-params-script)
7
+
8
+ # List all configured PagerDuty endpoints here
9
+ ENDPOINTS=(
10
+ anytime
11
+ workday
12
+ )
13
+
14
+ help=$(yarn -s ts-utils get-kwarg h "$@")
15
+
16
+ if [ -n "$help" ]; then
17
+ cat <<HEREDOC
18
+ Usage: $(basename ${BASH_SOURCE[0]}) [options]
19
+
20
+ Uploads PagerDuty endpoints to the AWS parameter store with proper tags
21
+
22
+ Options:
23
+ -h - display this help message and exit
24
+ -r - set AWS region - default: us-east-1
25
+
26
+ HEREDOC
27
+
28
+ exit 1
29
+ fi
30
+
31
+ interactive=true
32
+ environment=shared
33
+
34
+ printf "Find or create your PagerDuty service endpoints here: https://staxly.pagerduty.com/service-directory\n\n"
35
+
36
+ for endpoint in "${ENDPOINTS[@]}"; do
37
+ name="/external/pager_duty/$APPLICATION/${endpoint}_endpoint"
38
+
39
+ upload_parameter
40
+
41
+ echo
42
+ done
43
+
44
+ printf "\nDone uploading PagerDuty endpoints for $APPLICATION\n\n"
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env bash
2
+ # spell-checker: ignore pipefail kwarg sparameters
3
+ set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
4
+
5
+ source $(yarn -s ts-utils which init-constants-script)
6
+ source $(yarn -s ts-utils which init-params-script)
7
+
8
+ if [ -z "${PARAMS:-}" ]; then echo "PARAMS must be set" > /dev/stderr; exit 1; fi
9
+
10
+ environment=$(yarn -s ts-utils get-arg 0 "$@")
11
+
12
+ if [ -z "$environment" ]; then
13
+ cat <<HEREDOC
14
+ Usage: $(basename "${BASH_SOURCE[0]}") <environment> [options]
15
+
16
+ Uploads secret values from your environment to the AWS parameter store with proper tags
17
+
18
+ Options:
19
+ -o - overwrite existing parameters - default: don't overwrite
20
+ -p - upload set parameters, even if some are missing - default: abort if any are missing
21
+ -r - set AWS region - default: us-east-1
22
+
23
+ HEREDOC
24
+
25
+ exit 1
26
+ fi
27
+
28
+ overwrite=$(yarn -s ts-utils get-kwarg o "$@")
29
+ partial=$(yarn -s ts-utils get-kwarg p "$@")
30
+
31
+ # Check if any params are missing
32
+ params_with_value=
33
+ for param in "${PARAMS[@]}"; do
34
+ if [ -n "${!param:-}" ]; then
35
+ params_with_value="$params_with_value $param"
36
+ else
37
+ if [ -n "$partial" ]; then
38
+ echo "\"$param\" not uploaded as it is not set or not exported in your environment"
39
+ else
40
+ echo "\"$param\" is not set or not exported in your environment"
41
+ printf "Please set it first or use the -p option to upload only defined variables\n\n"
42
+ exit 1
43
+ fi
44
+ fi
45
+ done
46
+
47
+ if [ -z "$params_with_value" ]; then
48
+ printf '\nAborting: None of the parameters that could be uploaded have values\n\n'
49
+ exit 1
50
+ fi
51
+
52
+ for param in $params_with_value; do
53
+ name="$(get_param_name)"
54
+ value="${!param}"
55
+
56
+ upload_parameter
57
+ done
58
+
59
+ printf "\nSuccessfully uploaded %sparameters for %s-%s\n\n" "${partial:+partial }" "$environment" "$APPLICATION"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env bash
2
+ # spell-checker: ignore pipefail
3
+ set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
4
+
5
+ project_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." >/dev/null 2>&1 && pwd )"
6
+
7
+ file="$project_dir"/script/bin/"$1".bash
8
+
9
+ if [ ! -f "$file" ]; then
10
+ echo "$1 not found" > /dev/stderr;
11
+ exit 1;
12
+ fi;
13
+
14
+ echo "$file";
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env bash
2
+ # spell-checker: ignore pipefail
3
+ set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
4
+
5
+ project_dir="$(cd "$(dirname "$0")" && cd "$(dirname "$(readlink "$0")")/.." && pwd)"
6
+
7
+ script=${1-}
8
+
9
+ bin="$project_dir/script/bin/"
10
+ file="$bin$script.bash"
11
+
12
+ if [ -z "$script" ]; then
13
+ printf "specify a command\n\neg:\n yarn -s ts-utils [command name] [parameters]\n\n"
14
+
15
+ find "$bin" -name "*.bash" -exec basename {} \; | sed "s/\.bash//" | sort
16
+
17
+ echo
18
+ exit 1;
19
+ elif [ -n "$script" ] && [ ! -f "$file" ]; then
20
+ printf "%s is not a valid command. did you mean:\n\n" "$script"
21
+
22
+
23
+ find "$bin" -name "*$script*.bash" -exec basename {} \; | sed "s/\.bash//" | sort
24
+
25
+ echo
26
+ exit 1;
27
+ fi
28
+
29
+ shift
30
+ args=("$@")
31
+
32
+ # https://stackoverflow.com/a/61551944/14809536
33
+ "$file" "${args[@]+"${args[@]}"}"
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env bash
2
+ # spell-checker: ignore pipefail yargs mkdir withoutspecs
3
+ set -euo pipefail; if [ -n "${DEBUG-}" ]; then set -x; fi
4
+
5
+ project_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." >/dev/null 2>&1 && pwd )"
6
+
7
+ cd "$project_dir";
8
+
9
+ tsc_args=(--noEmit false --declaration)
10
+
11
+ if yarn -s ts-utils has-flag watch "$@"; then
12
+ tsc_args+=(--watch)
13
+ fi
14
+ if yarn -s ts-utils has-flag clean "$@"; then
15
+ rm -rf "$project_dir"/dist
16
+ fi
17
+
18
+ mkdir -p dist
19
+
20
+ yarn -s tsc --project tsconfig.without-specs.esm.json "${tsc_args[@]}"
21
+ yarn -s tsc --project tsconfig.without-specs.cjs.json "${tsc_args[@]}"