rename package from @push.rocks/npmextra to @push.rocks/smartconfig
- Rename all source files from npmextra.* to simpler names (classes.appdata.ts, etc.) - Rename Npmextra class to Smartconfig - Config file changed from npmextra.json to smartconfig.json - KV store path changed from ~/.npmextra/kv to ~/.smartconfig/kv - Update all imports, tests, and metadata
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
|
||||
// module to test
|
||||
import * as npmextra from '../ts/index.js';
|
||||
import * as smartconfig from '../ts/index.js';
|
||||
|
||||
interface ITestOptions {
|
||||
hi: string;
|
||||
@@ -11,10 +11,10 @@ interface ITestOptions {
|
||||
};
|
||||
}
|
||||
|
||||
let testAppdata: npmextra.AppData<ITestOptions>;
|
||||
let testAppdata: smartconfig.AppData<ITestOptions>;
|
||||
|
||||
tap.test('should create a valid AppData', async () => {
|
||||
testAppdata = new npmextra.AppData<ITestOptions>({
|
||||
testAppdata = new smartconfig.AppData<ITestOptions>({
|
||||
envMapping: {
|
||||
deep: {
|
||||
deep1: '',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import * as npmextra from '../ts/index.js';
|
||||
import * as smartconfig from '../ts/index.js';
|
||||
|
||||
// Test environment variable with boolean false value
|
||||
tap.test('should handle boolean false values in nested objects correctly', async () => {
|
||||
@@ -11,7 +11,7 @@ tap.test('should handle boolean false values in nested objects correctly', async
|
||||
process.env['S3_ACCESSSECRET'] = 'test-secret';
|
||||
|
||||
// Create AppData with nested object structure similar to CloudlyConfig
|
||||
const appData = await npmextra.AppData.createAndInit({
|
||||
const appData = await smartconfig.AppData.createAndInit({
|
||||
ephemeral: true, // Use in-memory storage for testing
|
||||
envMapping: {
|
||||
s3Descriptor: {
|
||||
@@ -40,7 +40,7 @@ tap.test('should handle boolean false values in nested objects correctly', async
|
||||
expect(s3Descriptor.region).toEqual('us-east-1');
|
||||
expect(s3Descriptor.accessKey).toEqual('test-key');
|
||||
expect(s3Descriptor.accessSecret).toEqual('test-secret');
|
||||
|
||||
|
||||
// Critical test: useSsl should be false, not undefined
|
||||
expect(s3Descriptor.useSsl).toEqual(false);
|
||||
expect(typeof s3Descriptor.useSsl).toEqual('boolean');
|
||||
@@ -68,8 +68,8 @@ tap.test('should handle various boolean representations correctly', async () =>
|
||||
|
||||
for (const testCase of testCases) {
|
||||
process.env['TEST_BOOL'] = testCase.env;
|
||||
|
||||
const appData = await npmextra.AppData.createAndInit({
|
||||
|
||||
const appData = await smartconfig.AppData.createAndInit({
|
||||
ephemeral: true,
|
||||
envMapping: {
|
||||
testBool: 'boolean:TEST_BOOL'
|
||||
@@ -86,7 +86,7 @@ tap.test('should handle various boolean representations correctly', async () =>
|
||||
|
||||
tap.test('should handle hardcoded boolean false values', async () => {
|
||||
// Test with hardcoded boolean false value
|
||||
const appData = await npmextra.AppData.createAndInit({
|
||||
const appData = await smartconfig.AppData.createAndInit({
|
||||
ephemeral: true,
|
||||
envMapping: {
|
||||
boolValue: 'hard_boolean:false'
|
||||
@@ -108,8 +108,8 @@ tap.test('should handle hardcoded boolean false values', async () => {
|
||||
tap.test('should not filter out other falsy values', async () => {
|
||||
process.env['ZERO_VALUE'] = '0';
|
||||
process.env['EMPTY_STRING'] = ''; // This should be preserved as empty string
|
||||
|
||||
const appData = await npmextra.AppData.createAndInit({
|
||||
|
||||
const appData = await smartconfig.AppData.createAndInit({
|
||||
ephemeral: true,
|
||||
envMapping: {
|
||||
nested: {
|
||||
@@ -136,4 +136,4 @@ tap.test('should not filter out other falsy values', async () => {
|
||||
expect(nested.hardcodedZero).toEqual('0');
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
export default tap.start();
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
|
||||
import * as npmextra from '../ts/index.js';
|
||||
import * as smartconfig from '../ts/index.js';
|
||||
|
||||
let myKeyValueStore: npmextra.KeyValueStore<any>;
|
||||
let myKeyValueStore: smartconfig.KeyValueStore<any>;
|
||||
|
||||
tap.test('should create a keyValueStore', async () => {
|
||||
myKeyValueStore = new npmextra.KeyValueStore<any>({
|
||||
myKeyValueStore = new smartconfig.KeyValueStore<any>({
|
||||
typeArg: 'custom',
|
||||
identityArg: 'test',
|
||||
customPath: 'test/somekv.json',
|
||||
});
|
||||
expect(myKeyValueStore).toBeInstanceOf(npmextra.KeyValueStore);
|
||||
expect(myKeyValueStore).toBeInstanceOf(smartconfig.KeyValueStore);
|
||||
});
|
||||
|
||||
tap.test('should reset the keyValueStore', async () => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import * as npmextra from '../ts/index.js';
|
||||
import * as smartconfig from '../ts/index.js';
|
||||
|
||||
// Test that sensitive values are properly redacted in logs
|
||||
tap.test('should redact sensitive values in console output', async () => {
|
||||
@@ -19,7 +19,7 @@ tap.test('should redact sensitive values in console output', async () => {
|
||||
process.env['DEBUG_MODE'] = 'true';
|
||||
|
||||
// Create AppData with sensitive environment mappings
|
||||
const appData = await npmextra.AppData.createAndInit({
|
||||
const appData = await smartconfig.AppData.createAndInit({
|
||||
ephemeral: true,
|
||||
envMapping: {
|
||||
apiKey: 'API_KEY',
|
||||
@@ -39,22 +39,22 @@ tap.test('should redact sensitive values in console output', async () => {
|
||||
|
||||
// Check that sensitive values were redacted in logs
|
||||
const combinedOutput = logOutput.join('\n');
|
||||
|
||||
|
||||
// API_KEY should be redacted
|
||||
expect(combinedOutput).toContain('sup...[26 chars]');
|
||||
expect(combinedOutput).not.toContain('super-secret-api-key-12345');
|
||||
|
||||
|
||||
// DATABASE_PASSWORD should be redacted
|
||||
expect(combinedOutput).toContain('myP...[13 chars]');
|
||||
expect(combinedOutput).not.toContain('myP@ssw0rd123');
|
||||
|
||||
|
||||
// AUTH_TOKEN should be redacted (JWT tokens starting with eyJ)
|
||||
expect(combinedOutput).toContain('eyJ...[');
|
||||
expect(combinedOutput).not.toContain('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9');
|
||||
|
||||
|
||||
// PUBLIC_URL should not be redacted (not sensitive)
|
||||
expect(combinedOutput).toContain('https://example.com');
|
||||
|
||||
|
||||
// DEBUG_MODE should not be redacted (not sensitive)
|
||||
expect(combinedOutput).toContain('true');
|
||||
|
||||
@@ -63,16 +63,16 @@ tap.test('should redact sensitive values in console output', async () => {
|
||||
const apiKey = await kvStore.readKey('apiKey');
|
||||
const dbPassword = await kvStore.readKey('dbPassword');
|
||||
const publicUrl = await kvStore.readKey('publicUrl');
|
||||
|
||||
|
||||
// Actual values should be stored correctly
|
||||
expect(apiKey).toEqual('super-secret-api-key-12345');
|
||||
expect(dbPassword).toEqual('myP@ssw0rd123');
|
||||
expect(publicUrl).toEqual('https://example.com');
|
||||
|
||||
|
||||
} finally {
|
||||
// Restore console.log in case of test failure
|
||||
console.log = originalLog;
|
||||
|
||||
|
||||
// Clean up environment variables
|
||||
delete process.env['API_KEY'];
|
||||
delete process.env['DATABASE_PASSWORD'];
|
||||
@@ -82,4 +82,4 @@ tap.test('should redact sensitive values in console output', async () => {
|
||||
}
|
||||
});
|
||||
|
||||
export default tap.start();
|
||||
export default tap.start();
|
||||
|
||||
18
test/test.ts
18
test/test.ts
@@ -1,31 +1,31 @@
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
|
||||
// module to test
|
||||
import * as npmextra from '../ts/index.js';
|
||||
import * as smartconfig from '../ts/index.js';
|
||||
|
||||
let testNpmextra: npmextra.Npmextra;
|
||||
let testSmartconfig: smartconfig.Smartconfig;
|
||||
|
||||
tap.test('should create a new Npmtextra instance', async () => {
|
||||
testNpmextra = new npmextra.Npmextra('./test/');
|
||||
expect(testNpmextra).toBeInstanceOf(npmextra.Npmextra);
|
||||
tap.test('should create a new Smartconfig instance', async () => {
|
||||
testSmartconfig = new smartconfig.Smartconfig('./test/');
|
||||
expect(testSmartconfig).toBeInstanceOf(smartconfig.Smartconfig);
|
||||
});
|
||||
|
||||
tap.test('should state wether a npmextra.json exists', async () => {
|
||||
tap.test('should state wether a smartconfig.json exists', async () => {
|
||||
// tslint:disable-next-line:no-unused-expression
|
||||
expect(testNpmextra.npmextraJsonExists).toBeTrue();
|
||||
expect(testSmartconfig.smartconfigJsonExists).toBeTrue();
|
||||
});
|
||||
|
||||
tap.test(
|
||||
'should pass through default value, if not overriden by config from file',
|
||||
async () => {
|
||||
let testData = testNpmextra.dataFor('testTool', { someKey2: 'someValue2' });
|
||||
let testData = testSmartconfig.dataFor('testTool', { someKey2: 'someValue2' });
|
||||
console.log(testData);
|
||||
expect(testData).toHaveProperty('someKey2');
|
||||
},
|
||||
);
|
||||
|
||||
tap.test('should read a config file', async () => {
|
||||
let testData = testNpmextra.dataFor<any>('testTool', {
|
||||
let testData = testSmartconfig.dataFor<any>('testTool', {
|
||||
someKey2: 'someValue2',
|
||||
});
|
||||
expect(testData).toHaveProperty('someKey2');
|
||||
|
||||
Reference in New Issue
Block a user