Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lokalise/node-core

Package Overview
Dependencies
Maintainers
5
Versions
107
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lokalise/node-core - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

dist/src/config/configValidators.d.ts

1

dist/index.d.ts

@@ -9,2 +9,3 @@ export { sendPut, sendPutBinary, sendDelete, sendPatch, sendGet, sendPost, httpClient, } from './src/http/httpClient';

export { ensureClosingSlashTransformer } from './src/config/configTransformers';
export { createRangeValidator } from './src/config/configValidators';
export type { EnvValueValidator, EnvValueTransformer, AppConfig, RedisConfig, } from './src/config/configTypes';

4

dist/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ensureClosingSlashTransformer = exports.ConfigScope = exports.InternalError = exports.PublicNonRecoverableError = exports.httpClient = exports.sendPost = exports.sendGet = exports.sendPatch = exports.sendDelete = exports.sendPutBinary = exports.sendPut = void 0;
exports.createRangeValidator = exports.ensureClosingSlashTransformer = exports.ConfigScope = exports.InternalError = exports.PublicNonRecoverableError = exports.httpClient = exports.sendPost = exports.sendGet = exports.sendPatch = exports.sendDelete = exports.sendPutBinary = exports.sendPut = void 0;
var httpClient_1 = require("./src/http/httpClient");

@@ -20,2 +20,4 @@ Object.defineProperty(exports, "sendPut", { enumerable: true, get: function () { return httpClient_1.sendPut; } });

Object.defineProperty(exports, "ensureClosingSlashTransformer", { enumerable: true, get: function () { return configTransformers_1.ensureClosingSlashTransformer; } });
var configValidators_1 = require("./src/config/configValidators");
Object.defineProperty(exports, "createRangeValidator", { enumerable: true, get: function () { return configValidators_1.createRangeValidator; } });
//# sourceMappingURL=index.js.map

@@ -0,1 +1,2 @@

import type { EnvValueValidator } from './configTypes';
export type EnvType = {

@@ -11,4 +12,5 @@ [key: string]: string | undefined;

getMandatoryOneOf<T>(param: string, supportedValues: T[]): T;
getMandatoryValidatedInteger(param: string, validator: EnvValueValidator<number>): number;
getOptionalNullable<T extends string | null | undefined>(param: string, defaultValue: T): T | string;
getOptionalValidated(param: string, defaultValue: string, validator: (value: string) => boolean): string;
getOptionalValidated(param: string, defaultValue: string, validator: EnvValueValidator<string>): string;
getOptionalTransformed(param: string, defaultValue: string, transformer: (value: string) => string): string;

@@ -15,0 +17,0 @@ getMandatoryTransformed(param: string, transformer: (value: string) => string): string;

@@ -38,2 +38,12 @@ "use strict";

}
getMandatoryValidatedInteger(param, validator) {
const value = this.getMandatoryInteger(param);
if (!validator(value)) {
throw new InternalError_1.InternalError({
message: `Value ${value} is invalid for parameter ${param}`,
errorCode: 'CONFIGURATION_ERROR',
});
}
return value;
}
getOptionalNullable(param, defaultValue) {

@@ -40,0 +50,0 @@ return this.env[param] ?? defaultValue;

@@ -7,2 +7,3 @@ "use strict";

const configTransformers_1 = require("./configTransformers");
const configValidators_1 = require("./configValidators");
describe('ConfigScope', () => {

@@ -27,2 +28,26 @@ describe('getMandatoryInteger', () => {

});
describe('getMandatoryValidatedInteger', () => {
const validator = (0, configValidators_1.createRangeValidator)(0, 15);
it('accepts a valid integer', () => {
process.env.value = '15';
const configScope = new ConfigScope_1.ConfigScope();
const resolvedValue = configScope.getMandatoryValidatedInteger('value', validator);
expect(resolvedValue).toBe(15);
});
it('throws an error on non-number', () => {
process.env.value = 'abc';
const configScope = new ConfigScope_1.ConfigScope();
expect(() => configScope.getMandatoryValidatedInteger('value', validator)).toThrow(/must be a number/);
});
it('throws an error on missing value', () => {
delete process.env.value;
const configScope = new ConfigScope_1.ConfigScope();
expect(() => configScope.getMandatoryInteger('value')).toThrow(/Missing mandatory configuration parameter/);
});
it('throws an error on invalid number', () => {
process.env.value = '16';
const configScope = new ConfigScope_1.ConfigScope();
expect(() => configScope.getMandatoryValidatedInteger('value', validator)).toThrow(/is invalid for parameter value/);
});
});
describe('getMandatory', () => {

@@ -29,0 +54,0 @@ it('accepts an integer', () => {

@@ -1,2 +0,2 @@

export type EnvValueValidator = (value: string | undefined | null) => boolean;
export type EnvValueValidator<InputType> = (value: InputType) => boolean;
export type EnvValueTransformer<InputType, OutputType> = (value: InputType) => OutputType;

@@ -3,0 +3,0 @@ export type RedisConfig = {

{
"name": "@lokalise/node-core",
"version": "2.1.0",
"version": "2.2.0",
"author": {

@@ -5,0 +5,0 @@ "name": "Lokalise",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc