@candlerip/shared 0.0.23 → 0.0.40

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 (96) hide show
  1. package/devops/cdk/cdk-deploy.sh +4 -4
  2. package/devops/docker/publish-to-docker-hub.sh +7 -7
  3. package/devops/environment/create-env-file.sh +0 -0
  4. package/devops/eslint/eslint.sh +4 -4
  5. package/devops/prettier/prettier.sh +4 -4
  6. package/package.json +36 -30
  7. package/src/devops/env-file/create-env-file/convert-environment-variable-name-to-ssm-parameter-name/index.d.ts +2 -0
  8. package/src/devops/env-file/create-env-file/convert-environment-variable-name-to-ssm-parameter-name/index.js +8 -0
  9. package/src/devops/env-file/create-env-file/convert-environment-variable-name-to-ssm-parameter-name/types.d.ts +2 -0
  10. package/src/devops/env-file/create-env-file/convert-environment-variable-name-to-ssm-parameter-name/types.js +1 -0
  11. package/src/devops/env-file/create-env-file/domains.d.ts +6 -0
  12. package/src/devops/env-file/create-env-file/domains.js +1 -0
  13. package/src/devops/env-file/create-env-file/index.d.ts +2 -0
  14. package/src/devops/env-file/create-env-file/index.js +41 -0
  15. package/src/devops/env-file/create-env-file/types.d.ts +6 -0
  16. package/src/devops/env-file/create-env-file/types.js +1 -0
  17. package/src/devops/env-file/create-env-file/validate-parameters/index.d.ts +2 -0
  18. package/src/devops/env-file/create-env-file/validate-parameters/index.js +52 -0
  19. package/src/devops/env-file/create-env-file/validate-parameters/types.d.ts +8 -0
  20. package/src/devops/env-file/create-env-file/validate-parameters/types.js +1 -0
  21. package/src/devops/env-file/index.d.ts +1 -0
  22. package/src/devops/env-file/index.js +1 -0
  23. package/src/devops/index.d.ts +1 -0
  24. package/src/devops/index.js +1 -0
  25. package/src/environment/environment-mode/domains.d.ts +1 -1
  26. package/src/environment/environment-mode/index.d.ts +3 -3
  27. package/src/environment/environment-mode/index.js +3 -3
  28. package/src/environment/environment-mode/type-guards/index.d.ts +3 -3
  29. package/src/environment/environment-mode/type-guards/index.js +3 -3
  30. package/src/environment/environment-mode/type-guards/is-environment-mode.d.ts +1 -1
  31. package/src/environment/environment-mode/type-guards/is-environment-mode.js +1 -1
  32. package/src/environment/environment-variable-name/constants.d.ts +2 -0
  33. package/src/environment/environment-variable-name/constants.js +28 -0
  34. package/src/environment/environment-variable-name/domains.d.ts +2 -2
  35. package/src/environment/environment-variable-name/index.d.ts +3 -1
  36. package/src/environment/environment-variable-name/index.js +3 -1
  37. package/src/environment/environment-variable-name/type-guards.d.ts +2 -0
  38. package/src/environment/environment-variable-name/type-guards.js +2 -0
  39. package/src/environment/environment-variables/domains.d.ts +1 -3
  40. package/src/environment/environment-variables/index.d.ts +1 -1
  41. package/src/environment/environment-variables/index.js +1 -1
  42. package/src/environment/index.d.ts +3 -3
  43. package/src/environment/index.js +3 -3
  44. package/src/error/domains.d.ts +14 -0
  45. package/src/error/domains.js +1 -0
  46. package/src/error/index.d.ts +3 -0
  47. package/src/error/index.js +3 -0
  48. package/src/error/utils/compose-error/index.d.ts +2 -0
  49. package/src/error/utils/compose-error/index.js +5 -0
  50. package/src/error/utils/compose-error/type.d.ts +2 -0
  51. package/src/error/utils/compose-error/type.js +1 -0
  52. package/src/error/utils/console-error/index.d.ts +2 -0
  53. package/src/error/utils/console-error/index.js +9 -0
  54. package/src/error/utils/console-error/type.d.ts +2 -0
  55. package/src/error/utils/console-error/type.js +1 -0
  56. package/src/error/utils/index.d.ts +2 -0
  57. package/src/error/utils/index.js +2 -0
  58. package/src/error/workers/index.d.ts +2 -0
  59. package/src/error/workers/index.js +32 -0
  60. package/src/error/workers/type.d.ts +19 -0
  61. package/src/error/workers/type.js +1 -0
  62. package/src/helpers/index.d.ts +2 -0
  63. package/src/helpers/index.js +2 -0
  64. package/src/helpers/reveal-all-object-props/index.d.ts +2 -0
  65. package/src/helpers/reveal-all-object-props/index.js +13 -0
  66. package/src/helpers/reveal-all-object-props/type.d.ts +1 -0
  67. package/src/helpers/reveal-all-object-props/type.js +1 -0
  68. package/src/helpers/stringify/index.d.ts +2 -0
  69. package/src/helpers/stringify/index.js +3 -0
  70. package/src/helpers/stringify/type.d.ts +1 -0
  71. package/src/helpers/stringify/type.js +1 -0
  72. package/src/index.d.ts +5 -3
  73. package/src/index.js +5 -3
  74. package/src/service/index.d.ts +2 -2
  75. package/src/service/index.js +2 -2
  76. package/src/service/service-environment-variable-names/constants.d.ts +1 -1
  77. package/src/service/service-environment-variable-names/constants.js +1 -1
  78. package/src/service/service-environment-variable-names/index.d.ts +1 -1
  79. package/src/service/service-environment-variable-names/index.js +1 -1
  80. package/src/service/service-environment-variable-names/type.d.ts +1 -1
  81. package/src/service/service-name/domains.d.ts +1 -1
  82. package/src/service/service-name/index.d.ts +3 -2
  83. package/src/service/service-name/index.js +3 -2
  84. package/src/service/service-name/type-guards.d.ts +2 -0
  85. package/src/service/service-name/type-guards.js +2 -0
  86. package/src/type/array/index.d.ts +1 -1
  87. package/src/type/array/index.js +1 -1
  88. package/src/type/index.d.ts +4 -4
  89. package/src/type/index.js +4 -4
  90. package/src/type/null/index.d.ts +1 -1
  91. package/src/type/null/index.js +1 -1
  92. package/src/type/object/index.d.ts +1 -1
  93. package/src/type/object/index.js +1 -1
  94. package/src/type/object/type-guards.js +2 -2
  95. package/src/type/string/index.d.ts +1 -1
  96. package/src/type/string/index.js +1 -1
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env sh
2
- set -e
3
-
4
- cdk deploy --require-approval never
1
+ #!/usr/bin/env sh
2
+ set -e
3
+
4
+ cdk deploy --require-approval never
@@ -1,7 +1,7 @@
1
- #!/usr/bin/env sh
2
-
3
- DOCKERFILE=${2:-"Dockerfile"}
4
-
5
- echo "$DOCKER_ACCESS_TOKEN" | docker login -u $DOCKER_USERNAME --password-stdin
6
- docker build -f $DOCKERFILE -t reveszimre/$1 .
7
- docker push reveszimre/$1
1
+ #!/usr/bin/env sh
2
+
3
+ DOCKERFILE=${2:-"Dockerfile"}
4
+
5
+ echo "$DOCKER_ACCESS_TOKEN" | docker login -u $DOCKER_USERNAME --password-stdin
6
+ docker build -f $DOCKERFILE -t reveszimre/$1 .
7
+ docker push reveszimre/$1
File without changes
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env sh
2
- set -e
3
-
4
- npx eslint .
1
+ #!/usr/bin/env sh
2
+ set -e
3
+
4
+ npx eslint .
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env sh
2
- set -e
3
-
4
- npx prettier . --write
1
+ #!/usr/bin/env sh
2
+ set -e
3
+
4
+ npx prettier . --write
package/package.json CHANGED
@@ -1,30 +1,36 @@
1
- {
2
- "name": "@candlerip/shared",
3
- "version": "0.0.23",
4
- "type": "module",
5
- "engines": {
6
- "node": "=22.19.0"
7
- },
8
- "main": "src/index.js",
9
- "bin": {
10
- "crs-cdk-deploy": "devops/cdk/cdk-deploy.sh",
11
- "crs-create-env-file": "devops/environment/create-env-file.sh",
12
- "crs-publish-to-docker-hub": "./devops/docker/publish-to-docker-hub.sh",
13
- "crs-eslint": "devops/eslint/eslint.sh",
14
- "crs-publish-to-npm-registry": "devops/npm/publish-to-npm-registry.sh",
15
- "crs-prettier": "devops/prettier/prettier.sh",
16
- "crs-tsc-build": "devops/typescript/tsc-build.sh",
17
- "crs-tsc-watch": "devops/typescript/tsc-watch.sh"
18
- },
19
- "scripts": {
20
- "dev": "sh ./devops/typescript/tsc-watch.sh"
21
- },
22
- "dependencies": {
23
- "eslint": "^9.28.0",
24
- "globals": "^16.2.0",
25
- "prettier": "^3.5.3",
26
- "tsc-alias": "^1.8.16",
27
- "typescript": "^5.8.3",
28
- "typescript-eslint": "^8.33.1"
29
- }
30
- }
1
+ {
2
+ "name": "@candlerip/shared",
3
+ "version": "0.0.40",
4
+ "type": "module",
5
+ "engines": {
6
+ "node": "=22.19.0"
7
+ },
8
+ "main": "src/index.js",
9
+ "bin": {
10
+ "crs-cdk-deploy": "devops/cdk/cdk-deploy.sh",
11
+ "crs-create-env-file": "src/devops/env-file/create-env-file/index.js",
12
+ "crs-publish-to-docker-hub": "./devops/docker/publish-to-docker-hub.sh",
13
+ "crs-eslint": "devops/eslint/eslint.sh",
14
+ "crs-publish-to-npm-registry": "devops/npm/publish-to-npm-registry.sh",
15
+ "crs-prettier": "devops/prettier/prettier.sh",
16
+ "crs-tsc-build": "devops/typescript/tsc-build.sh",
17
+ "crs-tsc-watch": "devops/typescript/tsc-watch.sh"
18
+ },
19
+ "scripts": {
20
+ "dev": "sh ./devops/typescript/tsc-watch.sh"
21
+ },
22
+ "dependencies": {
23
+ "@aws-sdk/client-ssm": "^3.917.0",
24
+ "eslint": "^9.28.0",
25
+ "globals": "^16.2.0",
26
+ "prettier": "^3.5.3",
27
+ "tsc-alias": "^1.8.16",
28
+ "typescript": "^5.8.3",
29
+ "typescript-eslint": "^8.33.1",
30
+ "yargs": "^18.0.0"
31
+ },
32
+ "devDependencies": {
33
+ "@types/node": "^24.9.1",
34
+ "@types/yargs": "^17.0.34"
35
+ }
36
+ }
@@ -0,0 +1,2 @@
1
+ import { ConvertEnvironmentVariableNameToSsmParameterName } from './types';
2
+ export declare const convertEnvironmentVariableNameToSsmParameterName: ConvertEnvironmentVariableNameToSsmParameterName;
@@ -0,0 +1,8 @@
1
+ import { MODE_INDEPENDENT_ENVIRONMENT_VARIABLE_NAMES } from '../../../../environment';
2
+ export const convertEnvironmentVariableNameToSsmParameterName = (environmentVariableName, environmentMode) => {
3
+ let parameterName = environmentVariableName;
4
+ if (!MODE_INDEPENDENT_ENVIRONMENT_VARIABLE_NAMES.includes(environmentVariableName)) {
5
+ parameterName = `${parameterName}_${environmentMode.toUpperCase()}`;
6
+ }
7
+ return parameterName.replace('AWS', 'AMAZONWEBSERVICES');
8
+ };
@@ -0,0 +1,2 @@
1
+ import { EnvironmentMode, EnvironmentVariableName } from '../../../../environment';
2
+ export type ConvertEnvironmentVariableNameToSsmParameterName = (environmentVariableName: EnvironmentVariableName, environmentMode: EnvironmentMode) => string;
@@ -0,0 +1,6 @@
1
+ export type Args = {
2
+ 'environment-mode'?: string;
3
+ 'environment-variable-name'?: string;
4
+ 'file-name'?: string;
5
+ 'service-name'?: string;
6
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env node
2
+ import { SERVICE_ENVIRONMENT_VARIABLE_NAMES } from '../../../service';
3
+ import { SSMClient, GetParametersCommand } from '@aws-sdk/client-ssm';
4
+ import * as fs from 'fs';
5
+ import { isEnvironmentMode } from '../../../environment';
6
+ import { validateParameters } from './validate-parameters';
7
+ import { convertEnvironmentVariableNameToSsmParameterName } from './convert-environment-variable-name-to-ssm-parameter-name';
8
+ const parameters = validateParameters();
9
+ if (parameters) {
10
+ const { environmentMode, environmentVariableName, fileName, serviceName } = parameters;
11
+ const ssmClient = new SSMClient();
12
+ let parameterNames = [];
13
+ if (environmentVariableName) {
14
+ parameterNames = [convertEnvironmentVariableNameToSsmParameterName(environmentVariableName, environmentMode)];
15
+ }
16
+ else if (serviceName) {
17
+ const envNames = SERVICE_ENVIRONMENT_VARIABLE_NAMES[serviceName];
18
+ parameterNames = envNames.map((envName) => convertEnvironmentVariableNameToSsmParameterName(envName, environmentMode));
19
+ }
20
+ const environmentVariables = {};
21
+ for (let i = 0; i < parameterNames.length; i += 10) {
22
+ const response = await ssmClient.send(new GetParametersCommand({
23
+ Names: parameterNames.slice(i, i + 10),
24
+ }));
25
+ parameterNames.forEach((parameterName) => {
26
+ let envName = parameterName.replace('AMAZONWEBSERVICES', 'AWS');
27
+ const parts = envName.split('_');
28
+ const lastPart = parts.pop()?.toLowerCase();
29
+ if (isEnvironmentMode(lastPart)) {
30
+ envName = parts.join('_');
31
+ }
32
+ const value = response.Parameters?.find((p) => p.Name === envName)?.Value;
33
+ environmentVariables[envName] = value;
34
+ });
35
+ fs.writeFileSync(fileName, environmentVariableName
36
+ ? Object.values(environmentVariables)[0]
37
+ : Object.entries(environmentVariables)
38
+ .map(([k, v]) => `${k}=${v}`)
39
+ .join('\n'), 'utf8');
40
+ }
41
+ }
@@ -0,0 +1,6 @@
1
+ export type Args = {
2
+ 'environment-mode'?: string;
3
+ 'environment-variable-name'?: string;
4
+ 'file-name'?: string;
5
+ 'service-name'?: string;
6
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { ValidateParameters } from './types';
2
+ export declare const validateParameters: ValidateParameters;
@@ -0,0 +1,52 @@
1
+ import { isServiceName } from '../../../../service';
2
+ import yargs from 'yargs';
3
+ import { hideBin } from 'yargs/helpers';
4
+ import { isString } from '../../../../type';
5
+ import { consoleError, ErrorWorker } from '../../../../error';
6
+ import { isEnvironmentMode, isEnvironmentVariableName } from '../../../../environment';
7
+ export const validateParameters = () => {
8
+ const argv = yargs(hideBin(process.argv)).parse();
9
+ const environmentMode = argv['environment-mode'];
10
+ const environmentVariableNameArg = argv['environment-variable-name'];
11
+ const serviceNameArg = argv['service-name'];
12
+ const fileName = argv['file-name'];
13
+ const { composeError } = ErrorWorker({
14
+ info: {
15
+ args: process.argv,
16
+ },
17
+ });
18
+ if (!isString(fileName)) {
19
+ consoleError(composeError('Invalid or missing file-name parameter'));
20
+ process.exit(1);
21
+ }
22
+ if (!isEnvironmentMode(environmentMode)) {
23
+ consoleError(composeError('Invalid environment-mode parameter'));
24
+ process.exit(1);
25
+ }
26
+ if (!environmentVariableNameArg && !serviceNameArg) {
27
+ consoleError(composeError('Missing environment-variable-name or service-name parameter'));
28
+ process.exit(1);
29
+ }
30
+ let environmentVariableName;
31
+ if (environmentVariableNameArg) {
32
+ if (!isEnvironmentVariableName(environmentVariableNameArg)) {
33
+ consoleError(composeError('Invalid environment-variable-name parameter'));
34
+ process.exit(1);
35
+ }
36
+ environmentVariableName = environmentVariableNameArg;
37
+ }
38
+ let serviceName;
39
+ if (serviceNameArg) {
40
+ if (!isServiceName(serviceNameArg)) {
41
+ consoleError(composeError('Invalid service-name parameter'));
42
+ process.exit(1);
43
+ }
44
+ serviceName = serviceNameArg;
45
+ }
46
+ return {
47
+ environmentMode,
48
+ environmentVariableName,
49
+ fileName,
50
+ serviceName,
51
+ };
52
+ };
@@ -0,0 +1,8 @@
1
+ import { ServiceName } from '../../../../service';
2
+ import { EnvironmentMode, EnvironmentVariableName } from '../../../../environment';
3
+ export type ValidateParameters = () => {
4
+ environmentMode: EnvironmentMode;
5
+ environmentVariableName?: EnvironmentVariableName;
6
+ fileName: string;
7
+ serviceName?: ServiceName;
8
+ } | void;
@@ -0,0 +1 @@
1
+ export * from './create-env-file';
@@ -0,0 +1 @@
1
+ export * from './create-env-file';
@@ -0,0 +1 @@
1
+ export * from './env-file';
@@ -0,0 +1 @@
1
+ export * from './env-file';
@@ -1,2 +1,2 @@
1
- import { ENVIRONMENT_MODES } from './constants.js';
1
+ import { ENVIRONMENT_MODES } from './constants';
2
2
  export type EnvironmentMode = (typeof ENVIRONMENT_MODES)[number];
@@ -1,3 +1,3 @@
1
- export * from './constants.js';
2
- export * from './domains.js';
3
- export * from './type-guards/index.js';
1
+ export * from './constants';
2
+ export * from './domains';
3
+ export * from './type-guards';
@@ -1,3 +1,3 @@
1
- export * from './constants.js';
2
- export * from './domains.js';
3
- export * from './type-guards/index.js';
1
+ export * from './constants';
2
+ export * from './domains';
3
+ export * from './type-guards';
@@ -1,3 +1,3 @@
1
- export * from './is-development.js';
2
- export * from './is-environment-mode.js';
3
- export * from './is-production.js';
1
+ export * from './is-development';
2
+ export * from './is-environment-mode';
3
+ export * from './is-production';
@@ -1,3 +1,3 @@
1
- export * from './is-development.js';
2
- export * from './is-environment-mode.js';
3
- export * from './is-production.js';
1
+ export * from './is-development';
2
+ export * from './is-environment-mode';
3
+ export * from './is-production';
@@ -1,2 +1,2 @@
1
- import { EnvironmentMode } from '../domains.js';
1
+ import { EnvironmentMode } from '../domains';
2
2
  export declare const isEnvironmentMode: (data?: unknown) => data is EnvironmentMode;
@@ -1,2 +1,2 @@
1
- import { ENVIRONMENT_MODES } from '../constants.js';
1
+ import { ENVIRONMENT_MODES } from '../constants';
2
2
  export const isEnvironmentMode = (data) => ENVIRONMENT_MODES.some((it) => data === it);
@@ -0,0 +1,2 @@
1
+ export declare const ENVIRONMENT_VARIABLE_NAMES: readonly ["APP_NAME", "APP_PORT", "AWS_REGION", "AWS_S3_IMAGES_BUCKET_NAME", "CACHE_SERVICE_PORT", "DATABASE_URL", "DOMAIN_NAME", "FRONTEND_URL", "LOGGER_SERVICE_PORT", "MOBILE_APP_URL", "NODE_ENV", "RABBITMQ_URL", "REDIS_PWD", "REDIS_URL", "REDIS_URL_APP", "SSL_PRIVATE_KEY"];
2
+ export declare const MODE_INDEPENDENT_ENVIRONMENT_VARIABLE_NAMES: readonly ["APP_NAME", "APP_PORT", "AWS_REGION", "CACHE_SERVICE_PORT", "DOMAIN_NAME", "LOGGER_SERVICE_PORT", "REDIS_PWD", "SSL_PRIVATE_KEY"];
@@ -0,0 +1,28 @@
1
+ export const ENVIRONMENT_VARIABLE_NAMES = [
2
+ 'APP_NAME',
3
+ 'APP_PORT',
4
+ 'AWS_REGION',
5
+ 'AWS_S3_IMAGES_BUCKET_NAME',
6
+ 'CACHE_SERVICE_PORT',
7
+ 'DATABASE_URL',
8
+ 'DOMAIN_NAME',
9
+ 'FRONTEND_URL',
10
+ 'LOGGER_SERVICE_PORT',
11
+ 'MOBILE_APP_URL',
12
+ 'NODE_ENV',
13
+ 'RABBITMQ_URL',
14
+ 'REDIS_PWD',
15
+ 'REDIS_URL',
16
+ 'REDIS_URL_APP',
17
+ 'SSL_PRIVATE_KEY',
18
+ ];
19
+ export const MODE_INDEPENDENT_ENVIRONMENT_VARIABLE_NAMES = [
20
+ 'APP_NAME',
21
+ 'APP_PORT',
22
+ 'AWS_REGION',
23
+ 'CACHE_SERVICE_PORT',
24
+ 'DOMAIN_NAME',
25
+ 'LOGGER_SERVICE_PORT',
26
+ 'REDIS_PWD',
27
+ 'SSL_PRIVATE_KEY',
28
+ ];
@@ -1,2 +1,2 @@
1
- import { EnvironmentVariables } from '../environment-variables/index.js';
2
- export type EnvironmentVariableName = keyof EnvironmentVariables;
1
+ import { ENVIRONMENT_VARIABLE_NAMES } from './constants';
2
+ export type EnvironmentVariableName = (typeof ENVIRONMENT_VARIABLE_NAMES)[number];
@@ -1 +1,3 @@
1
- export * from './domains.js';
1
+ export * from './constants';
2
+ export * from './domains';
3
+ export * from './type-guards';
@@ -1 +1,3 @@
1
- export * from './domains.js';
1
+ export * from './constants';
2
+ export * from './domains';
3
+ export * from './type-guards';
@@ -0,0 +1,2 @@
1
+ import { EnvironmentVariableName } from './domains';
2
+ export declare const isEnvironmentVariableName: (data?: unknown) => data is EnvironmentVariableName;
@@ -0,0 +1,2 @@
1
+ import { ENVIRONMENT_VARIABLE_NAMES } from './constants';
2
+ export const isEnvironmentVariableName = (data) => ENVIRONMENT_VARIABLE_NAMES.some((it) => data === it);
@@ -1,14 +1,12 @@
1
- import { EnvironmentMode } from '../environment-mode/index.js';
1
+ import { EnvironmentMode } from '../environment-mode';
2
2
  export type EnvironmentVariables = {
3
3
  APP_NAME: string;
4
4
  APP_PORT: number;
5
5
  AWS_REGION: string;
6
6
  AWS_S3_IMAGES_BUCKET_NAME: string;
7
7
  CACHE_SERVICE_PORT: number;
8
- CACHE_ENABLED: boolean;
9
8
  DATABASE_URL: string;
10
9
  DOMAIN_NAME: string;
11
- EC2_IP_ADDRESS: string;
12
10
  FRONTEND_URL: string;
13
11
  LOGGER_SERVICE_PORT: number;
14
12
  MOBILE_APP_URL: string;
@@ -1 +1 @@
1
- export * from './domains.js';
1
+ export * from './domains';
@@ -1 +1 @@
1
- export * from './domains.js';
1
+ export * from './domains';
@@ -1,3 +1,3 @@
1
- export * from './environment-mode/index.js';
2
- export * from './environment-variable-name/index.js';
3
- export * from './environment-variables/index.js';
1
+ export * from './environment-mode';
2
+ export * from './environment-variable-name';
3
+ export * from './environment-variables';
@@ -1,3 +1,3 @@
1
- export * from './environment-mode/index.js';
2
- export * from './environment-variable-name/index.js';
3
- export * from './environment-variables/index.js';
1
+ export * from './environment-mode';
2
+ export * from './environment-variable-name';
3
+ export * from './environment-variables';
@@ -0,0 +1,14 @@
1
+ export interface Error {
2
+ id: string;
3
+ info?: ErrorInfo;
4
+ message: ErrorMessage;
5
+ }
6
+ export type ErrorInfo = Record<string, unknown>;
7
+ export type ErrorMessage = string;
8
+ export type TError<T = never> = {
9
+ data: T;
10
+ error?: never;
11
+ } | {
12
+ error: Error;
13
+ data?: never;
14
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export * from './domains';
2
+ export * from './utils';
3
+ export * from './workers';
@@ -0,0 +1,3 @@
1
+ export * from './domains';
2
+ export * from './utils';
3
+ export * from './workers';
@@ -0,0 +1,2 @@
1
+ import { ComposeError } from './type';
2
+ export declare const composeError: ComposeError;
@@ -0,0 +1,5 @@
1
+ export const composeError = (message, info) => ({
2
+ id: Math.random().toString(16).slice(2).toUpperCase(),
3
+ info,
4
+ message: message ?? '',
5
+ });
@@ -0,0 +1,2 @@
1
+ import { Error, ErrorInfo, ErrorMessage } from '../../domains';
2
+ export type ComposeError = (message?: ErrorMessage, info?: ErrorInfo) => Error;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { ConsoleError } from './type';
2
+ export declare const consoleError: ConsoleError;
@@ -0,0 +1,9 @@
1
+ import { stringify } from '../../../helpers';
2
+ export const consoleError = (error) => {
3
+ const { id, info, message } = error;
4
+ let msg = `ERROR: ${message} (ID) ${id}`;
5
+ if (info) {
6
+ msg += ` (INFO) ${stringify(info)}`;
7
+ }
8
+ console.error(msg);
9
+ };
@@ -0,0 +1,2 @@
1
+ import { Error } from '../../domains';
2
+ export type ConsoleError = (error: Error) => void;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from './compose-error';
2
+ export * from './console-error';
@@ -0,0 +1,2 @@
1
+ export * from './compose-error';
2
+ export * from './console-error';
@@ -0,0 +1,2 @@
1
+ import { ErrorWorkerType } from './type';
2
+ export declare const ErrorWorker: ErrorWorkerType;
@@ -0,0 +1,32 @@
1
+ import { composeError as composeErrorFunc } from '../utils';
2
+ export const ErrorWorker = (props) => {
3
+ let _error = props ? composeErrorFunc(props.message, props.info) : undefined;
4
+ const _composeInfo = (info) => {
5
+ if (_error) {
6
+ _error.info = {
7
+ ..._error.info,
8
+ ...info,
9
+ };
10
+ return;
11
+ }
12
+ _error = composeErrorFunc(undefined, info);
13
+ };
14
+ const addErrorInfo = (info) => {
15
+ _composeInfo(info);
16
+ };
17
+ const addErrorMessage = (message) => {
18
+ _error = composeErrorFunc(message);
19
+ };
20
+ const composeError = (message, info) => composeErrorFunc(message, info ?? _error?.info);
21
+ const getError = () => (_error ? { error: _error } : undefined);
22
+ const resetError = () => {
23
+ _error = undefined;
24
+ };
25
+ return {
26
+ addErrorInfo,
27
+ addErrorMessage,
28
+ composeError,
29
+ getError,
30
+ resetError,
31
+ };
32
+ };
@@ -0,0 +1,19 @@
1
+ import { Error, ErrorInfo, ErrorMessage } from '../domains';
2
+ export type ErrorWorkerType = (props?: {
3
+ message?: ErrorMessage;
4
+ info?: ErrorInfo;
5
+ }) => {
6
+ addErrorInfo: AddErrorInfo;
7
+ addErrorMessage: AddErrorMessage;
8
+ composeError: ComposeError;
9
+ getError: GetError;
10
+ resetError: ResetError;
11
+ };
12
+ export type _ComposeInfo = (info?: ErrorInfo) => void;
13
+ export type AddErrorInfo = (info: ErrorInfo) => void;
14
+ export type AddErrorMessage = (message: ErrorMessage) => void;
15
+ export type ComposeError = (message: ErrorMessage, info?: ErrorInfo) => Error;
16
+ export type GetError = () => {
17
+ error: Error;
18
+ } | undefined;
19
+ export type ResetError = () => void;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from './reveal-all-object-props';
2
+ export * from './stringify';
@@ -0,0 +1,2 @@
1
+ export * from './reveal-all-object-props';
2
+ export * from './stringify';
@@ -0,0 +1,2 @@
1
+ import { RevealAllObjectProps } from './type';
2
+ export declare const revealAllObjectProps: RevealAllObjectProps;
@@ -0,0 +1,13 @@
1
+ import { isObject } from '../../type';
2
+ export const revealAllObjectProps = (obj) => {
3
+ const newObj = {};
4
+ Object.getOwnPropertyNames(obj).forEach((key) => {
5
+ if (isObject(obj[key])) {
6
+ newObj[key] = revealAllObjectProps(obj[key]);
7
+ }
8
+ else {
9
+ newObj[key] = obj[key];
10
+ }
11
+ });
12
+ return newObj;
13
+ };
@@ -0,0 +1 @@
1
+ export type RevealAllObjectProps = (obj: Record<string, unknown>) => Record<string, unknown>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { Stringify } from './type';
2
+ export declare const stringify: Stringify;
@@ -0,0 +1,3 @@
1
+ import { isObject } from '../../type';
2
+ import { revealAllObjectProps } from '../reveal-all-object-props';
3
+ export const stringify = (obj) => JSON.stringify(isObject(obj) ? revealAllObjectProps(obj) : obj);
@@ -0,0 +1 @@
1
+ export type Stringify = (obj: unknown) => string;
@@ -0,0 +1 @@
1
+ export {};
package/src/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
- export * from './environment/index.js';
2
- export * from './service/index.js';
3
- export * from './type/index.js';
1
+ export * from './environment';
2
+ export * from './error';
3
+ export * from './helpers';
4
+ export * from './service';
5
+ export * from './type';
package/src/index.js CHANGED
@@ -1,3 +1,5 @@
1
- export * from './environment/index.js';
2
- export * from './service/index.js';
3
- export * from './type/index.js';
1
+ export * from './environment';
2
+ export * from './error';
3
+ export * from './helpers';
4
+ export * from './service';
5
+ export * from './type';
@@ -1,2 +1,2 @@
1
- export * from './service-environment-variable-names/index.js';
2
- export * from './service-name/index.js';
1
+ export * from './service-environment-variable-names';
2
+ export * from './service-name';
@@ -1,2 +1,2 @@
1
- export * from './service-environment-variable-names/index.js';
2
- export * from './service-name/index.js';
1
+ export * from './service-environment-variable-names';
2
+ export * from './service-name';
@@ -1,2 +1,2 @@
1
- import { ServiceEnvironmentVariableNames } from './type.js';
1
+ import { ServiceEnvironmentVariableNames } from './type';
2
2
  export declare const SERVICE_ENVIRONMENT_VARIABLE_NAMES: ServiceEnvironmentVariableNames;
@@ -1,5 +1,5 @@
1
1
  export const SERVICE_ENVIRONMENT_VARIABLE_NAMES = {
2
2
  'environment-service': ['APP_NAME'],
3
3
  'cache-service': ['APP_NAME', 'MOBILE_APP_URL'],
4
- nginx: ['APP_PORT', 'EC2_IP_ADDRESS', 'SSL_PRIVATE_KEY'],
4
+ nginx: ['APP_PORT', 'SSL_PRIVATE_KEY'],
5
5
  };
@@ -1 +1 @@
1
- export * from './constants.js';
1
+ export * from './constants';
@@ -1 +1 @@
1
- export * from './constants.js';
1
+ export * from './constants';
@@ -1,5 +1,5 @@
1
1
  import { EnvironmentVariableName } from 'src/environment';
2
- import { ServiceName } from '../service-name/index.js';
2
+ import { ServiceName } from '../service-name';
3
3
  export type ServiceEnvironmentVariableNames = {
4
4
  [key in ServiceName]: EnvironmentVariableName[];
5
5
  };
@@ -1,2 +1,2 @@
1
- import { SERVICE_NAMES } from './constants.js';
1
+ import { SERVICE_NAMES } from './constants';
2
2
  export type ServiceName = (typeof SERVICE_NAMES)[number];
@@ -1,2 +1,3 @@
1
- export * from './constants.js';
2
- export * from './domains.js';
1
+ export * from './constants';
2
+ export * from './domains';
3
+ export * from './type-guards';
@@ -1,2 +1,3 @@
1
- export * from './constants.js';
2
- export * from './domains.js';
1
+ export * from './constants';
2
+ export * from './domains';
3
+ export * from './type-guards';
@@ -0,0 +1,2 @@
1
+ import { ServiceName } from './domains';
2
+ export declare const isServiceName: (data?: unknown) => data is ServiceName;
@@ -0,0 +1,2 @@
1
+ import { SERVICE_NAMES } from './constants';
2
+ export const isServiceName = (data) => SERVICE_NAMES.some((it) => data === it);
@@ -1 +1 @@
1
- export * from './type-guards.js';
1
+ export * from './type-guards';
@@ -1 +1 @@
1
- export * from './type-guards.js';
1
+ export * from './type-guards';
@@ -1,4 +1,4 @@
1
- export * from './array/index.js';
2
- export * from './null/index.js';
3
- export * from './object/index.js';
4
- export * from './string/index.js';
1
+ export * from './array';
2
+ export * from './null';
3
+ export * from './object';
4
+ export * from './string';
package/src/type/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export * from './array/index.js';
2
- export * from './null/index.js';
3
- export * from './object/index.js';
4
- export * from './string/index.js';
1
+ export * from './array';
2
+ export * from './null';
3
+ export * from './object';
4
+ export * from './string';
@@ -1 +1 @@
1
- export * from './type-guards.js';
1
+ export * from './type-guards';
@@ -1 +1 @@
1
- export * from './type-guards.js';
1
+ export * from './type-guards';
@@ -1 +1 @@
1
- export * from './type-guards.js';
1
+ export * from './type-guards';
@@ -1 +1 @@
1
- export * from './type-guards.js';
1
+ export * from './type-guards';
@@ -1,5 +1,5 @@
1
- import { isArray } from '../array/index.js';
2
- import { isNull } from '../null/index.js';
1
+ import { isArray } from '../array';
2
+ import { isNull } from '../null';
3
3
  export const isObject = (data) => {
4
4
  if (typeof data !== 'object') {
5
5
  return false;
@@ -1 +1 @@
1
- export * from './type-guards.js';
1
+ export * from './type-guards';
@@ -1 +1 @@
1
- export * from './type-guards.js';
1
+ export * from './type-guards';