@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,10 +1,85 @@
1
1
  declare type AssertionFailed = string | Error | (() => never) | undefined;
2
+ /**
3
+ * Asserts that the given value is true.
4
+ *
5
+ * @param x The value to assert.
6
+ * @param failed The error to throw if the assertion fails. It is STRONGLY encouraged
7
+ * to provide some value for this for traceability. Passing an Error instead of a string
8
+ * makes the stack trace more useful and allows you to handle assertion failures differently.
9
+ * @example const definitelyTrue = assertTrue(randomThing, new Error('thing was not true'));
10
+ * @returns the value that was asserted
11
+ */
2
12
  export declare const assertTrue: <X>(x: X, failed?: AssertionFailed) => X & true;
13
+ /**
14
+ * Asserts that the given value is false.
15
+ *
16
+ * @param x The value to assert.
17
+ * @param failed The error to throw if the assertion fails. It is STRONGLY encouraged
18
+ * to provide some value for this for traceability. Passing an Error instead of a string
19
+ * makes the stack trace more useful and allows you to handle assertion failures differently.
20
+ * @example const definitelyFalse = assertFalse(randomThing, new Error('thing was not false'));
21
+ * @returns the value that was asserted
22
+ */
3
23
  export declare const assertFalse: <X>(x: X, failed?: AssertionFailed) => X & false;
24
+ /**
25
+ * Asserts that the given value is defined.
26
+ *
27
+ * @param x The value to assert.
28
+ * @param failed The error to throw if the assertion fails. It is STRONGLY encouraged
29
+ * to provide some value for this for traceability. Passing an Error instead of a string
30
+ * makes the stack trace more useful and allows you to handle assertion failures differently.
31
+ * @example const definitelyDefined = assertDefined(randomThing, new Error('thing was undefined'));
32
+ * @returns the value that was asserted, with a type that excludes undefined
33
+ */
4
34
  export declare const assertDefined: <X>(x: X, failed?: AssertionFailed) => Exclude<X, undefined>;
35
+ /**
36
+ * Asserts that the given value is a string.
37
+ *
38
+ * @param x The value to assert.
39
+ * @param failed The error to throw if the assertion fails. It is STRONGLY encouraged
40
+ * to provide some value for this for traceability. Passing an Error instead of a string
41
+ * makes the stack trace more useful and allows you to handle assertion failures differently.
42
+ * @example const definitelyAString = assertString(randomThing, new Error('thing is not a string'));
43
+ * @returns the value that was asserted
44
+ */
5
45
  export declare const assertString: <X>(x: X, failed?: AssertionFailed) => string;
46
+ /**
47
+ * Asserts that the given value is not `NaN`. Does not assert that the value is a number.
48
+ *
49
+ * @param thing The value to assert.
50
+ * @param failed The error to throw if the assertion fails. It is STRONGLY encouraged
51
+ * to provide some value for this for traceability. Passing an Error instead of a string
52
+ * makes the stack trace more useful and allows you to handle assertion failures differently.
53
+ * @example const definitelyNotNotANumber = assertNotNaN(randomThing, new Error('thing was NaN'));
54
+ * @returns the value that was asserted
55
+ */
6
56
  export declare const assertNotNaN: <T>(thing: T, failed?: AssertionFailed) => T;
57
+ /**
58
+ * @deprecated use assertNotNaN instead
59
+ */
7
60
  export declare const notNaN: <T>(thing: T, failed?: AssertionFailed) => T;
61
+ /**
62
+ * Asserts that the first argument is an instance of the second.
63
+ *
64
+ * @param thing The value to assert.
65
+ * @param constructable The class to check against.
66
+ * @param failed The error to throw if the assertion fails. It is STRONGLY encouraged
67
+ * to provide some value for this for traceability. Passing an Error instead of a string
68
+ * makes the stack trace more useful and allows you to handle assertion failures differently.
69
+ * @example const definitelySyntaxError = assertInstanceOf(error, SyntaxError, new Error('argument was not a SyntaxError'));
70
+ * @returns the value that was asserted
71
+ */
8
72
  export declare const assertInstanceOf: <T>(thing: any, constructable: Function & (new (...args: any[]) => T), failed?: AssertionFailed) => T;
73
+ /**
74
+ * Asserts that the error in the first argument is an instance of the error given as the
75
+ * second argument
76
+ *
77
+ * @param thing The value to assert.
78
+ * @param constructable The error class to check against.
79
+ * @example const definitelySyntaxError = assertInstanceOf(error, SyntaxError);
80
+ * @returns the value that was asserted
81
+ * @throws the original error if the check fails
82
+ * @see assertInstanceOf
83
+ */
9
84
  export declare const assertErrorInstanceOf: <T extends Error>(thing: unknown, constructable: Function & (new (...args: any[]) => T)) => T;
10
85
  export {};
@@ -1,4 +1,17 @@
1
1
  "use strict";
2
+ /*
3
+ * all of these assertions take either a string, throw function, or nothing
4
+ * for the second argument. its STRONGLY encouraged to provide some error
5
+ * or message that explains the reason for the assertion
6
+ *
7
+ * eg:
8
+ * assertDefined(user, new UnauthorizedException())
9
+ * assertDefined(thing.otherThing, 'otherThing should be guaranteed to exist, but is missing')
10
+ *
11
+ * passing an Error instead of a string makes the first element of the resulting
12
+ * stack trace more useful, and allows you to use specific error types
13
+ * that might be handled differently.
14
+ */
2
15
  Object.defineProperty(exports, "__esModule", { value: true });
3
16
  exports.assertErrorInstanceOf = exports.assertInstanceOf = exports.notNaN = exports.assertNotNaN = exports.assertString = exports.assertDefined = exports.assertFalse = exports.assertTrue = void 0;
4
17
  const doThrow = (failed) => {
@@ -13,10 +26,15 @@ const doThrow = (failed) => {
13
26
  }
14
27
  return failed();
15
28
  };
16
- /*
17
- * see note above about the failure case in the second argument
29
+ /**
30
+ * Asserts that the given value is true.
18
31
  *
19
- * const definitelyTrue = assertTrue(randomThing);
32
+ * @param x The value to assert.
33
+ * @param failed The error to throw if the assertion fails. It is STRONGLY encouraged
34
+ * to provide some value for this for traceability. Passing an Error instead of a string
35
+ * makes the stack trace more useful and allows you to handle assertion failures differently.
36
+ * @example const definitelyTrue = assertTrue(randomThing, new Error('thing was not true'));
37
+ * @returns the value that was asserted
20
38
  */
21
39
  const assertTrue = (x, failed) => {
22
40
  if (typeof x !== 'boolean' || x !== true) {
@@ -25,10 +43,15 @@ const assertTrue = (x, failed) => {
25
43
  return x;
26
44
  };
27
45
  exports.assertTrue = assertTrue;
28
- /*
29
- * see note above about the failure case in the second argument
46
+ /**
47
+ * Asserts that the given value is false.
30
48
  *
31
- * const definitelyFalse = assertFalse(randomThing);
49
+ * @param x The value to assert.
50
+ * @param failed The error to throw if the assertion fails. It is STRONGLY encouraged
51
+ * to provide some value for this for traceability. Passing an Error instead of a string
52
+ * makes the stack trace more useful and allows you to handle assertion failures differently.
53
+ * @example const definitelyFalse = assertFalse(randomThing, new Error('thing was not false'));
54
+ * @returns the value that was asserted
32
55
  */
33
56
  const assertFalse = (x, failed) => {
34
57
  if (typeof x !== 'boolean' || x !== false) {
@@ -37,10 +60,15 @@ const assertFalse = (x, failed) => {
37
60
  return x;
38
61
  };
39
62
  exports.assertFalse = assertFalse;
40
- /*
41
- * see note above about the failure case in the second argument
63
+ /**
64
+ * Asserts that the given value is defined.
42
65
  *
43
- * const definitelyDefined = assertDefined(randomThing);
66
+ * @param x The value to assert.
67
+ * @param failed The error to throw if the assertion fails. It is STRONGLY encouraged
68
+ * to provide some value for this for traceability. Passing an Error instead of a string
69
+ * makes the stack trace more useful and allows you to handle assertion failures differently.
70
+ * @example const definitelyDefined = assertDefined(randomThing, new Error('thing was undefined'));
71
+ * @returns the value that was asserted, with a type that excludes undefined
44
72
  */
45
73
  const assertDefined = (x, failed) => {
46
74
  if (x === undefined) {
@@ -49,10 +77,15 @@ const assertDefined = (x, failed) => {
49
77
  return x;
50
78
  };
51
79
  exports.assertDefined = assertDefined;
52
- /*
53
- * see note above about the failure case in the second argument
80
+ /**
81
+ * Asserts that the given value is a string.
54
82
  *
55
- * const definitelyAString = assertString(randomThing);
83
+ * @param x The value to assert.
84
+ * @param failed The error to throw if the assertion fails. It is STRONGLY encouraged
85
+ * to provide some value for this for traceability. Passing an Error instead of a string
86
+ * makes the stack trace more useful and allows you to handle assertion failures differently.
87
+ * @example const definitelyAString = assertString(randomThing, new Error('thing is not a string'));
88
+ * @returns the value that was asserted
56
89
  */
57
90
  const assertString = (x, failed) => {
58
91
  if (typeof x !== 'string') {
@@ -61,14 +94,15 @@ const assertString = (x, failed) => {
61
94
  return x;
62
95
  };
63
96
  exports.assertString = assertString;
64
- /*
65
- * see note above about the failure case in the second argument
66
- *
67
- * this doesn't assert that the thing is a number, it just asserts that its not
68
- * the actual NaN value
97
+ /**
98
+ * Asserts that the given value is not `NaN`. Does not assert that the value is a number.
69
99
  *
70
- * eg:
71
- * const definitelyNotNotANumber = assertNotNaN(randomThing);
100
+ * @param thing The value to assert.
101
+ * @param failed The error to throw if the assertion fails. It is STRONGLY encouraged
102
+ * to provide some value for this for traceability. Passing an Error instead of a string
103
+ * makes the stack trace more useful and allows you to handle assertion failures differently.
104
+ * @example const definitelyNotNotANumber = assertNotNaN(randomThing, new Error('thing was NaN'));
105
+ * @returns the value that was asserted
72
106
  */
73
107
  const assertNotNaN = (thing, failed) => {
74
108
  if (typeof thing === 'number' && isNaN(thing)) {
@@ -77,15 +111,20 @@ const assertNotNaN = (thing, failed) => {
77
111
  return thing;
78
112
  };
79
113
  exports.assertNotNaN = assertNotNaN;
80
- // deprecated function name
114
+ /**
115
+ * @deprecated use assertNotNaN instead
116
+ */
81
117
  exports.notNaN = exports.assertNotNaN;
82
- /*
83
- * unlike other guards, this one takes 2 arguments
84
- *
85
- * the second argument is the class that we are checking against
118
+ /**
119
+ * Asserts that the first argument is an instance of the second.
86
120
  *
87
- * eg:
88
- * const definitelySyntaxError = assertInstanceOf(error, SyntaxError);
121
+ * @param thing The value to assert.
122
+ * @param constructable The class to check against.
123
+ * @param failed The error to throw if the assertion fails. It is STRONGLY encouraged
124
+ * to provide some value for this for traceability. Passing an Error instead of a string
125
+ * makes the stack trace more useful and allows you to handle assertion failures differently.
126
+ * @example const definitelySyntaxError = assertInstanceOf(error, SyntaxError, new Error('argument was not a SyntaxError'));
127
+ * @returns the value that was asserted
89
128
  */
90
129
  const assertInstanceOf = (thing, constructable, failed) => {
91
130
  if (thing instanceof constructable) {
@@ -94,10 +133,16 @@ const assertInstanceOf = (thing, constructable, failed) => {
94
133
  return doThrow(failed);
95
134
  };
96
135
  exports.assertInstanceOf = assertInstanceOf;
97
- /*
98
- * like assertInstanceOf but only for error classes
136
+ /**
137
+ * Asserts that the error in the first argument is an instance of the error given as the
138
+ * second argument
99
139
  *
100
- * rethrows the original error if the check fails
140
+ * @param thing The value to assert.
141
+ * @param constructable The error class to check against.
142
+ * @example const definitelySyntaxError = assertInstanceOf(error, SyntaxError);
143
+ * @returns the value that was asserted
144
+ * @throws the original error if the check fails
145
+ * @see assertInstanceOf
101
146
  */
102
147
  const assertErrorInstanceOf = (thing, constructable) => {
103
148
  if (thing instanceof Error) {
@@ -1,2 +1,5 @@
1
1
  import { SSM } from '@aws-sdk/client-ssm';
2
+ /**
3
+ * A memoized instance of the AWS SSM client.
4
+ */
2
5
  export declare const ssmService: () => SSM;
@@ -3,4 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ssmService = void 0;
4
4
  const client_ssm_1 = require("@aws-sdk/client-ssm");
5
5
  const __1 = require("..");
6
+ /**
7
+ * A memoized instance of the AWS SSM client.
8
+ */
6
9
  exports.ssmService = (0, __1.once)(() => new client_ssm_1.SSM({ apiVersion: '2012-08-10' }));
@@ -1,2 +1,10 @@
1
1
  import { ConfigValueProvider } from '.';
2
+ /**
3
+ * Returns a value from the AWS Parameter Store.
4
+ *
5
+ * @param parameterName the name of the parameter; can be a literal name (string) or can itself
6
+ * be accessed via another parameter by giving a configuration value provider.
7
+ * @example const someValue = resolveConfig(awsParameterConfig('some-parameter-name'));
8
+ * @returns the configuration value provider for the value
9
+ */
2
10
  export declare const awsParameterConfig: (parameterName: ConfigValueProvider<string>) => ConfigValueProvider<string>;
@@ -5,6 +5,14 @@ const client_ssm_1 = require("@aws-sdk/client-ssm");
5
5
  const assertions_1 = require("../assertions");
6
6
  const ssmService_1 = require("../aws/ssmService");
7
7
  const resolveConfigValue_1 = require("./resolveConfigValue");
8
+ /**
9
+ * Returns a value from the AWS Parameter Store.
10
+ *
11
+ * @param parameterName the name of the parameter; can be a literal name (string) or can itself
12
+ * be accessed via another parameter by giving a configuration value provider.
13
+ * @example const someValue = resolveConfig(awsParameterConfig('some-parameter-name'));
14
+ * @returns the configuration value provider for the value
15
+ */
8
16
  const awsParameterConfig = (parameterName) => {
9
17
  return async () => {
10
18
  const command = new client_ssm_1.GetParameterCommand({ Name: await (0, resolveConfigValue_1.resolveConfigValue)(parameterName), WithDecryption: true });
@@ -1,3 +1,24 @@
1
1
  import { ConfigValueProvider } from '.';
2
+ /**
3
+ * A list of environment variables that were requested at build time. Used by webpack to
4
+ * capture build-time environment variables values.
5
+ */
2
6
  export declare const ENV_BUILD_CONFIGS: string[];
7
+ /**
8
+ * Returns an environment variable from the process environment. Depending on the `type` in the
9
+ * call to get the variable, the variable's value may be what it was at build time, not at runtime.
10
+ * The return value is not the variable value itself, but rather a provider that has to be called
11
+ * to read the variable value (meaning, this is safe to call even if the variable doesn't exist,
12
+ * because someone else later needs to call the provider to get the value -- that call may explode,
13
+ * but this one won't).
14
+ *
15
+ * @param name The name of the environment variable to retrieve.
16
+ * @param type The mode for accessing the variable. Defaults to `'build'`, i.e. getting the
17
+ * variable as it was set at build time (webpack is connected here to make this possible). This
18
+ * argument can also be `'runtime'` in which case the value at build time is ignored and the
19
+ * variable is pulled live from `process.env`.
20
+ * @param [defaultValue] The default value to use if the variable is not found.
21
+ *
22
+ * @example const config = { configValue: envConfig('environment_variable_name') };
23
+ */
3
24
  export declare const envConfig: (name: string, type?: 'build' | 'runtime', defaultValue?: string | undefined) => ConfigValueProvider<string>;
@@ -3,22 +3,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.envConfig = exports.ENV_BUILD_CONFIGS = void 0;
4
4
  const assertions_1 = require("../assertions");
5
5
  const guards_1 = require("../guards");
6
- /*
7
- * uses a config from the process environment.
8
- *
9
- * there are two modes for this, by default it expects the value to be provided at build time,
10
- * and there is access built in here for webpack to provide the configs. if you pass `runtime`
11
- * as the second argument it skips the build logic and will try to literally pull it from
12
- * `process.env` when the config is used at runtime
6
+ /**
7
+ * A list of environment variables that were requested at build time. Used by webpack to
8
+ * capture build-time environment variables values.
9
+ */
10
+ exports.ENV_BUILD_CONFIGS = [];
11
+ /**
12
+ * Returns an environment variable from the process environment. Depending on the `type` in the
13
+ * call to get the variable, the variable's value may be what it was at build time, not at runtime.
14
+ * The return value is not the variable value itself, but rather a provider that has to be called
15
+ * to read the variable value (meaning, this is safe to call even if the variable doesn't exist,
16
+ * because someone else later needs to call the provider to get the value -- that call may explode,
17
+ * but this one won't).
13
18
  *
14
- * the value is read from the environment when something tries to use it, not when `envConfig` is called.
19
+ * @param name The name of the environment variable to retrieve.
20
+ * @param type The mode for accessing the variable. Defaults to `'build'`, i.e. getting the
21
+ * variable as it was set at build time (webpack is connected here to make this possible). This
22
+ * argument can also be `'runtime'` in which case the value at build time is ignored and the
23
+ * variable is pulled live from `process.env`.
24
+ * @param [defaultValue] The default value to use if the variable is not found.
15
25
  *
16
- * eg:
17
- * const config = {
18
- * configValue: envConfig('environment_variable_name'),
19
- * };
20
- * */
21
- exports.ENV_BUILD_CONFIGS = [];
26
+ * @example const config = { configValue: envConfig('environment_variable_name') };
27
+ */
22
28
  const envConfig = (name, type = 'build', defaultValue) => {
23
29
  if (type === 'build') {
24
30
  exports.ENV_BUILD_CONFIGS.push(name);
@@ -1,18 +1,46 @@
1
+ /**
2
+ * A simple type alias for a string that represents a configuration value. Currently only string values are supported to maintain compatibility with environment variables, but this type is future proofing against allowing other types like `number` as possible config values.
3
+ */
1
4
  export declare type ConfigValue = string;
5
+ /**
6
+ * A configuration object that may contain nested configuration objects or configuration values.
7
+ */
2
8
  export declare type Config = {
3
9
  [key: string]: Config | ConfigValue;
4
10
  };
11
+ /**
12
+ * Either a function that returns a `ConfigValue` or a `Promise` that resolves to a `ConfigValue`,
13
+ * or just a `ConfigValue`.
14
+ */
5
15
  export declare type ConfigValueProvider<V extends ConfigValue = ConfigValue> = (() => Promise<V> | V) | V;
16
+ /**
17
+ * A configuration object that may contain nested configuration objects or configuration value providers.
18
+ */
6
19
  export declare type ConfigProvider = {
7
20
  [key: string]: ConfigProvider | ConfigValueProvider;
8
21
  };
22
+ /**
23
+ * Conditional type that resolves to the type of configuration object for the given configuration
24
+ * provider. Also resolves to a config value type if the given type is a config value.
25
+ */
9
26
  export declare type ConfigForConfigProvider<T> = T extends ConfigValue ? T : T extends ConfigProvider ? {
10
27
  [key in keyof T]: ConfigForConfigProvider<T[key]>;
11
28
  } : T extends ConfigValueProvider<infer R> ? R : never;
29
+ /**
30
+ * Conditional type that resolves to the `ConfigProvider` type for the given configuration
31
+ * type (`ConfigValue` or `Config`). The resulting type is either a `ConfigValueProvider` or
32
+ * a `ConfigProvider`.
33
+ */
12
34
  export declare type ConfigProviderForConfig<T> = T extends ConfigValue ? ConfigValueProvider<T> : T extends Config ? {
13
35
  [key in keyof T]: ConfigProviderForConfig<T[key]>;
14
36
  } : never;
15
37
  export * from './resolveConfigValue';
38
+ /**
39
+ * stub, mostly for testing. sometimes it helps please typescript to use this if you have
40
+ * two configs you want to have the same type but one is a fixed string and one is a complicated provider
41
+ *
42
+ * @example const config = { configValue: stubConfig('just-a-string') };
43
+ */
16
44
  export declare const stubConfig: <V extends string>(configValue: V) => ConfigValueProvider<V>;
17
45
  export * from './envConfig';
18
46
  export * from './replaceConfig';
@@ -21,15 +21,12 @@ __exportStar(require("./resolveConfigValue"), exports);
21
21
  * re-usable config providers
22
22
  * ===========
23
23
  * */
24
- /*
24
+ /**
25
25
  * stub, mostly for testing. sometimes it helps please typescript to use this if you have
26
26
  * two configs you want to have the same type but one is a fixed string and one is a complicated provider
27
27
  *
28
- * eg:
29
- * const config = {
30
- * configValue: stubConfig('just-a-string'),
31
- * };
32
- * */
28
+ * @example const config = { configValue: stubConfig('just-a-string') };
29
+ */
33
30
  const stubConfig = (configValue) => configValue;
34
31
  exports.stubConfig = stubConfig;
35
32
  __exportStar(require("./envConfig"), exports);
@@ -1,2 +1,12 @@
1
1
  import { ConfigValueProvider } from '.';
2
+ /**
3
+ * Returns a value from the AWS Parameter Store. Can only be used during in AWS Lambda, and
4
+ * requires that the AWS Parameters and Secrets Lambda Extension Layer be included in the Lambda.
5
+ * This extension has built-in caching for requested parameters.
6
+ *
7
+ * @param parameterName the name of the parameter; can be a literal name (string) or can itself
8
+ * be accessed via another parameter by giving a configuration value provider.
9
+ * @example const someValue = resolveConfig(lambdaParameterConfig('some-parameter-name'));
10
+ * @returns the configuration value provider for the value
11
+ */
2
12
  export declare const lambdaParameterConfig: (parameterName: ConfigValueProvider<string>) => ConfigValueProvider<string>;
@@ -11,8 +11,16 @@ const envConfig_1 = require("./envConfig");
11
11
  const _1 = require(".");
12
12
  const lambdaExtensionUrl = 'http://localhost:2773';
13
13
  let lambdaExtensionReadyPromise;
14
- // NOTE: Can only be used during in AWS Lambda
15
- // The AWS Parameters and Secrets Lambda Extension Layer must be included in the Lambda function
14
+ /**
15
+ * Returns a value from the AWS Parameter Store. Can only be used during in AWS Lambda, and
16
+ * requires that the AWS Parameters and Secrets Lambda Extension Layer be included in the Lambda.
17
+ * This extension has built-in caching for requested parameters.
18
+ *
19
+ * @param parameterName the name of the parameter; can be a literal name (string) or can itself
20
+ * be accessed via another parameter by giving a configuration value provider.
21
+ * @example const someValue = resolveConfig(lambdaParameterConfig('some-parameter-name'));
22
+ * @returns the configuration value provider for the value
23
+ */
16
24
  const lambdaParameterConfig = (parameterName) => async () => {
17
25
  const token = await (0, _1.resolveConfigValue)((0, envConfig_1.envConfig)('AWS_SESSION_TOKEN', 'runtime'));
18
26
  const name = await (0, _1.resolveConfigValue)(parameterName);
@@ -1,4 +1,14 @@
1
1
  import { ConfigValueProvider } from '.';
2
+ /**
3
+ * Substitutes configuration values into a provided string.
4
+ * Performs a string substitution using configuration values
5
+ * @param base The string into which substitutions will be made; contains tokens that are
6
+ * referenced in the `replacements` argument.
7
+ * @param replacements A map of tokens to configuration value providers. The providers are
8
+ * resolved and the values are substituted into the `base` string, replacing the tokens.
9
+ * @example replaceConfig('https://[host]', { '[host]': envConfig('HOST') })
10
+ * @returns the string after substitution is complete
11
+ */
2
12
  export declare const replaceConfig: (base: ConfigValueProvider<string>, replacements: {
3
13
  [token: string]: ConfigValueProvider<string>;
4
14
  }) => ConfigValueProvider<string>;
@@ -2,6 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.replaceConfig = void 0;
4
4
  const resolveConfigValue_1 = require("./resolveConfigValue");
5
+ /**
6
+ * Substitutes configuration values into a provided string.
7
+ * Performs a string substitution using configuration values
8
+ * @param base The string into which substitutions will be made; contains tokens that are
9
+ * referenced in the `replacements` argument.
10
+ * @param replacements A map of tokens to configuration value providers. The providers are
11
+ * resolved and the values are substituted into the `base` string, replacing the tokens.
12
+ * @example replaceConfig('https://[host]', { '[host]': envConfig('HOST') })
13
+ * @returns the string after substitution is complete
14
+ */
5
15
  const replaceConfig = (base, replacements) => {
6
16
  return async () => {
7
17
  const resolved = await Promise.all(Object.entries(replacements)
@@ -1,2 +1,5 @@
1
1
  import { ConfigValueProvider } from '.';
2
+ /**
3
+ * resolves a config value into a string, to be used inside of things that are provided configurations
4
+ */
2
5
  export declare const resolveConfigValue: <V extends string>(provider: ConfigValueProvider<V>) => Promise<V>;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveConfigValue = void 0;
4
- /*
4
+ /**
5
5
  * resolves a config value into a string, to be used inside of things that are provided configurations
6
- * */
6
+ */
7
7
  const resolveConfigValue = async (provider) => {
8
8
  return typeof provider === 'function'
9
9
  ? await provider()
@@ -1,23 +1,50 @@
1
+ /**
2
+ * Returns true if the error is defined in this library
3
+ */
1
4
  export declare const isAppError: (e: any) => e is Error & {
2
5
  constructor: {
3
6
  TYPE: string;
4
7
  };
5
8
  };
9
+ /**
10
+ * Invalid request error
11
+ *
12
+ * `InvalidRequestError.matches(error)` is a reliable way to check if an error is an
13
+ * `InvalidRequestError`; `instanceof` checks may not work if code is split into multiple bundles
14
+ */
6
15
  export declare class InvalidRequestError extends Error {
7
16
  static readonly TYPE = "InvalidRequestError";
8
17
  static matches: (e: any) => e is typeof InvalidRequestError;
9
18
  constructor(message?: string);
10
19
  }
20
+ /**
21
+ * Unauthorized error
22
+ *
23
+ * `UnauthorizedError.matches(error)` is a reliable way to check if an error is an
24
+ * `UnauthorizedError`; `instanceof` checks may not work if code is split into multiple bundles
25
+ */
11
26
  export declare class UnauthorizedError extends Error {
12
27
  static readonly TYPE = "UnauthorizedError";
13
28
  static matches: (e: any) => e is typeof UnauthorizedError;
14
29
  constructor(message?: string);
15
30
  }
31
+ /**
32
+ * Not found error
33
+ *
34
+ * `NotFoundError.matches(error)` is a reliable way to check if an error is a
35
+ * `NotFoundError`; `instanceof` checks may not work if code is split into multiple bundles
36
+ */
16
37
  export declare class NotFoundError extends Error {
17
38
  static readonly TYPE = "NotFoundError";
18
39
  static matches: (e: any) => e is typeof NotFoundError;
19
40
  constructor(message?: string);
20
41
  }
42
+ /**
43
+ * Session expired error
44
+ *
45
+ * `SessionExpiredError.matches(error)` is a reliable way to check if an error is a
46
+ * `SessionExpiredError`; `instanceof` checks may not work if code is split into multiple bundles
47
+ */
21
48
  export declare class SessionExpiredError extends Error {
22
49
  static readonly TYPE = "SessionExpiredError";
23
50
  static matches: (e: any) => e is typeof SessionExpiredError;
@@ -1,6 +1,4 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SessionExpiredError = exports.NotFoundError = exports.UnauthorizedError = exports.InvalidRequestError = exports.isAppError = void 0;
4
2
  /*
5
3
  * if code is split into multiple bundles, sometimes each bundle
6
4
  * will get its own definition of this module and then instanceof checks
@@ -13,11 +11,22 @@ exports.SessionExpiredError = exports.NotFoundError = exports.UnauthorizedError
13
11
  * error instanceof InvalidRequestError
14
12
  *
15
13
  */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.SessionExpiredError = exports.NotFoundError = exports.UnauthorizedError = exports.InvalidRequestError = exports.isAppError = void 0;
16
16
  const errorIsType = ({ TYPE }) => (e) => e instanceof Error
17
17
  && e.constructor.TYPE === TYPE;
18
+ /**
19
+ * Returns true if the error is defined in this library
20
+ */
18
21
  const isAppError = (e) => e instanceof Error
19
22
  && typeof e.constructor.TYPE === 'string';
20
23
  exports.isAppError = isAppError;
24
+ /**
25
+ * Invalid request error
26
+ *
27
+ * `InvalidRequestError.matches(error)` is a reliable way to check if an error is an
28
+ * `InvalidRequestError`; `instanceof` checks may not work if code is split into multiple bundles
29
+ */
21
30
  class InvalidRequestError extends Error {
22
31
  constructor(message) {
23
32
  super(message || InvalidRequestError.TYPE);
@@ -26,6 +35,12 @@ class InvalidRequestError extends Error {
26
35
  exports.InvalidRequestError = InvalidRequestError;
27
36
  InvalidRequestError.TYPE = 'InvalidRequestError';
28
37
  InvalidRequestError.matches = errorIsType(InvalidRequestError);
38
+ /**
39
+ * Unauthorized error
40
+ *
41
+ * `UnauthorizedError.matches(error)` is a reliable way to check if an error is an
42
+ * `UnauthorizedError`; `instanceof` checks may not work if code is split into multiple bundles
43
+ */
29
44
  class UnauthorizedError extends Error {
30
45
  constructor(message) {
31
46
  super(message || UnauthorizedError.TYPE);
@@ -34,6 +49,12 @@ class UnauthorizedError extends Error {
34
49
  exports.UnauthorizedError = UnauthorizedError;
35
50
  UnauthorizedError.TYPE = 'UnauthorizedError';
36
51
  UnauthorizedError.matches = errorIsType(UnauthorizedError);
52
+ /**
53
+ * Not found error
54
+ *
55
+ * `NotFoundError.matches(error)` is a reliable way to check if an error is a
56
+ * `NotFoundError`; `instanceof` checks may not work if code is split into multiple bundles
57
+ */
37
58
  class NotFoundError extends Error {
38
59
  constructor(message) {
39
60
  super(message || NotFoundError.TYPE);
@@ -42,6 +63,12 @@ class NotFoundError extends Error {
42
63
  exports.NotFoundError = NotFoundError;
43
64
  NotFoundError.TYPE = 'NotFoundError';
44
65
  NotFoundError.matches = errorIsType(NotFoundError);
66
+ /**
67
+ * Session expired error
68
+ *
69
+ * `SessionExpiredError.matches(error)` is a reliable way to check if an error is a
70
+ * `SessionExpiredError`; `instanceof` checks may not work if code is split into multiple bundles
71
+ */
45
72
  class SessionExpiredError extends Error {
46
73
  constructor(message) {
47
74
  super(message || SessionExpiredError.TYPE);