@candlerip/shared 0.0.23 → 0.0.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/devops/npm/publish-to-npm-registry.sh +5 -1
- package/package.json +9 -3
- package/src/devops/env-file/create-env-file/convert-environment-variable-name-to-ssm-parameter-name/index.d.ts +2 -0
- package/src/devops/env-file/create-env-file/convert-environment-variable-name-to-ssm-parameter-name/index.js +8 -0
- package/src/devops/env-file/create-env-file/convert-environment-variable-name-to-ssm-parameter-name/types.d.ts +2 -0
- package/src/devops/env-file/create-env-file/convert-environment-variable-name-to-ssm-parameter-name/types.js +1 -0
- package/src/devops/env-file/create-env-file/index.d.ts +2 -0
- package/src/devops/env-file/create-env-file/index.js +41 -0
- package/src/devops/env-file/create-env-file/types.d.ts +6 -0
- package/src/devops/env-file/create-env-file/types.js +1 -0
- package/src/devops/env-file/create-env-file/validate-parameters/index.d.ts +2 -0
- package/src/devops/env-file/create-env-file/validate-parameters/index.js +52 -0
- package/src/devops/env-file/create-env-file/validate-parameters/types.d.ts +8 -0
- package/src/devops/env-file/create-env-file/validate-parameters/types.js +1 -0
- package/src/devops/env-file/index.d.ts +1 -0
- package/src/devops/env-file/index.js +1 -0
- package/src/devops/index.d.ts +1 -0
- package/src/devops/index.js +1 -0
- package/src/environment/environment-variable-name/constants.d.ts +2 -0
- package/src/environment/environment-variable-name/constants.js +28 -0
- package/src/environment/environment-variable-name/domains.d.ts +2 -2
- package/src/environment/environment-variable-name/index.d.ts +2 -0
- package/src/environment/environment-variable-name/index.js +2 -0
- package/src/environment/environment-variable-name/type-guards.d.ts +2 -0
- package/src/environment/environment-variable-name/type-guards.js +2 -0
- package/src/environment/environment-variables/domains.d.ts +0 -2
- package/src/error/domains.d.ts +14 -0
- package/src/error/domains.js +1 -0
- package/src/error/index.d.ts +3 -0
- package/src/error/index.js +3 -0
- package/src/error/utils/compose-error/index.d.ts +2 -0
- package/src/error/utils/compose-error/index.js +5 -0
- package/src/error/utils/compose-error/type.d.ts +2 -0
- package/src/error/utils/compose-error/type.js +1 -0
- package/src/error/utils/console-error/index.d.ts +2 -0
- package/src/error/utils/console-error/index.js +9 -0
- package/src/error/utils/console-error/type.d.ts +2 -0
- package/src/error/utils/console-error/type.js +1 -0
- package/src/error/utils/index.d.ts +2 -0
- package/src/error/utils/index.js +2 -0
- package/src/error/workers/index.d.ts +2 -0
- package/src/error/workers/index.js +32 -0
- package/src/error/workers/type.d.ts +19 -0
- package/src/error/workers/type.js +1 -0
- package/src/helpers/index.d.ts +2 -0
- package/src/helpers/index.js +2 -0
- package/src/helpers/reveal-all-object-props/index.d.ts +2 -0
- package/src/helpers/reveal-all-object-props/index.js +13 -0
- package/src/helpers/reveal-all-object-props/type.d.ts +1 -0
- package/src/helpers/reveal-all-object-props/type.js +1 -0
- package/src/helpers/stringify/index.d.ts +2 -0
- package/src/helpers/stringify/index.js +3 -0
- package/src/helpers/stringify/type.d.ts +1 -0
- package/src/helpers/stringify/type.js +1 -0
- package/src/index.d.ts +2 -0
- package/src/index.js +2 -0
- package/src/service/service-environment-variable-names/constants.js +1 -2
- package/src/service/service-name/constants.d.ts +1 -1
- package/src/service/service-name/constants.js +1 -1
- package/src/service/service-name/index.d.ts +1 -0
- package/src/service/service-name/index.js +1 -0
- package/src/service/service-name/type-guards.d.ts +2 -0
- package/src/service/service-name/type-guards.js +2 -0
|
@@ -3,9 +3,13 @@ set -e
|
|
|
3
3
|
|
|
4
4
|
npm config set //registry.npmjs.org/:_authToken $NPM_ACCESS_TOKEN
|
|
5
5
|
|
|
6
|
+
ls -al
|
|
7
|
+
cat package.json
|
|
8
|
+
cat ~/.npmrc
|
|
9
|
+
|
|
6
10
|
if [ -d "devops" ]; then
|
|
7
11
|
cp -r devops dist
|
|
8
12
|
fi
|
|
9
13
|
cp package.json dist
|
|
10
14
|
|
|
11
|
-
npm publish ./dist --access
|
|
15
|
+
npm publish ./dist --access public
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@candlerip/shared",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.42",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": "=22.19.0"
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"main": "src/index.js",
|
|
9
9
|
"bin": {
|
|
10
10
|
"crs-cdk-deploy": "devops/cdk/cdk-deploy.sh",
|
|
11
|
-
"crs-create-env-file": "devops/
|
|
11
|
+
"crs-create-env-file": "src/devops/env-file/create-env-file/index.js",
|
|
12
12
|
"crs-publish-to-docker-hub": "./devops/docker/publish-to-docker-hub.sh",
|
|
13
13
|
"crs-eslint": "devops/eslint/eslint.sh",
|
|
14
14
|
"crs-publish-to-npm-registry": "devops/npm/publish-to-npm-registry.sh",
|
|
@@ -20,11 +20,17 @@
|
|
|
20
20
|
"dev": "sh ./devops/typescript/tsc-watch.sh"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
+
"@aws-sdk/client-ssm": "^3.917.0",
|
|
23
24
|
"eslint": "^9.28.0",
|
|
24
25
|
"globals": "^16.2.0",
|
|
25
26
|
"prettier": "^3.5.3",
|
|
26
27
|
"tsc-alias": "^1.8.16",
|
|
27
28
|
"typescript": "^5.8.3",
|
|
28
|
-
"typescript-eslint": "^8.33.1"
|
|
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"
|
|
29
35
|
}
|
|
30
36
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MODE_INDEPENDENT_ENVIRONMENT_VARIABLE_NAMES } from '../../../../environment/index.js';
|
|
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 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { SERVICE_ENVIRONMENT_VARIABLE_NAMES } from '../../../service/index.js';
|
|
3
|
+
import { SSMClient, GetParametersCommand } from '@aws-sdk/client-ssm';
|
|
4
|
+
import * as fs from 'fs';
|
|
5
|
+
import { isEnvironmentMode } from '../../../environment/index.js';
|
|
6
|
+
import { validateParameters } from './validate-parameters/index.js';
|
|
7
|
+
import { convertEnvironmentVariableNameToSsmParameterName } from './convert-environment-variable-name-to-ssm-parameter-name/index.js';
|
|
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 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { isServiceName } from '../../../../service/index.js';
|
|
2
|
+
import yargs from 'yargs';
|
|
3
|
+
import { hideBin } from 'yargs/helpers';
|
|
4
|
+
import { isString } from '../../../../type/index.js';
|
|
5
|
+
import { consoleError, ErrorWorker } from '../../../../error/index.js';
|
|
6
|
+
import { isEnvironmentMode, isEnvironmentVariableName } from '../../../../environment/index.js';
|
|
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/index.js';
|
|
2
|
+
import { EnvironmentMode, EnvironmentVariableName } from '../../../../environment/index.js';
|
|
3
|
+
export type ValidateParameters = () => {
|
|
4
|
+
environmentMode: EnvironmentMode;
|
|
5
|
+
environmentVariableName?: EnvironmentVariableName;
|
|
6
|
+
fileName: string;
|
|
7
|
+
serviceName?: ServiceName;
|
|
8
|
+
} | void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './create-env-file/index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './create-env-file/index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './env-file/index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './env-file/index.js';
|
|
@@ -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 {
|
|
2
|
-
export type EnvironmentVariableName =
|
|
1
|
+
import { ENVIRONMENT_VARIABLE_NAMES } from './constants.js';
|
|
2
|
+
export type EnvironmentVariableName = (typeof ENVIRONMENT_VARIABLE_NAMES)[number];
|
|
@@ -5,10 +5,8 @@ export type EnvironmentVariables = {
|
|
|
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;
|
|
@@ -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 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { stringify } from '../../../helpers/index.js';
|
|
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 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { composeError as composeErrorFunc } from '../utils/index.js';
|
|
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.js';
|
|
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,13 @@
|
|
|
1
|
+
import { isObject } from '../../type/index.js';
|
|
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 @@
|
|
|
1
|
+
export type Stringify = (obj: unknown) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/src/index.d.ts
CHANGED
package/src/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SERVICE_NAMES: readonly ["cache-service", "nginx"
|
|
1
|
+
export declare const SERVICE_NAMES: readonly ["cache-service", "nginx"];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SERVICE_NAMES = ['cache-service', 'nginx'
|
|
1
|
+
export const SERVICE_NAMES = ['cache-service', 'nginx'];
|