New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

linkbox-price-service

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

linkbox-price-service - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

lib/prices.json

20

lib/price-calculator.d.ts

@@ -13,20 +13,6 @@ export declare class CalculateProps {

declare type Price = {
base: number;
channel: number;
listener: number;
cloudStreaming?: number;
oneTimePrice: number;
periodicPrice: number;
};
export declare class PriceCalculator {
private prices;
calculate(props: CalculateProps): Promise<{
variablePrice: number;
periodicPrice: number;
}>;
getPrice(props: CalculateProps): Promise<Price>;
private variablePrice;
private fixPrice;
private oneTimePrice;
private periodicPrice;
private loadPrices;
}
export default function calculatePrice(props: CalculateProps): Price;
export {};
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PriceCalculator = exports.CalculateProps = void 0;
var axios_1 = require("axios");
var _ = require("lodash");
exports.CalculateProps = void 0;
var _ = __importStar(require("lodash"));
var prices_json_1 = __importDefault(require("./prices.json"));
var CalculateProps = /** @class */ (function () {

@@ -57,96 +43,49 @@ function CalculateProps() {

exports.CalculateProps = CalculateProps;
var PriceCalculator = /** @class */ (function () {
function PriceCalculator() {
function calculatePrice(props) {
var prices = getPrice(props);
return {
oneTimePrice: oneTimePrice(prices, props),
periodicPrice: periodicPrice(prices, props),
};
}
exports.default = calculatePrice;
function getPrice(props) {
var path = props.intercom ? 'intercom' : 'audiocast';
path += props.hardware ? '.hardware' : '.cloud';
if (props.buyLicense) {
path += props.hardware ? '.buying.monthly' : '.monthly';
}
PriceCalculator.prototype.calculate = function (props) {
return __awaiter(this, void 0, void 0, function () {
var price;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.getPrice(props)];
case 1:
price = _a.sent();
console.log({
variablePrice: this.variablePrice(price, props),
periodicPrice: this.periodicPrice(price, props),
});
return [2 /*return*/, {
variablePrice: this.variablePrice(price, props),
periodicPrice: this.periodicPrice(price, props),
}];
}
});
});
};
PriceCalculator.prototype.getPrice = function (props) {
return __awaiter(this, void 0, void 0, function () {
var path, _a, price;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
path = props.intercom ? 'intercom' : 'audiocast';
path += props.hardware ? '.hardware' : '.cloud';
if (props.buyLicense) {
path += props.hardware ? '.buying.monthly' : '.monthly';
}
else {
if (props.hardware) {
path += props.buyHardware ? '.buying' : '.leasing';
}
path += props.daily ? '.daily' : '.monthly';
}
if (!!this.prices) return [3 /*break*/, 2];
_a = this;
return [4 /*yield*/, this.loadPrices()];
case 1:
_a.prices = _b.sent();
_b.label = 2;
case 2:
price = _.get(this.prices, path, null);
return [2 /*return*/, _.mapValues(price, props.currency)];
}
});
});
};
PriceCalculator.prototype.variablePrice = function (price, props) {
var variablePrice = price.channel * props.channels + price.listener * props.listeners;
return props.cloudStreaming && price.cloudStreaming ? variablePrice + price.cloudStreaming : variablePrice;
};
PriceCalculator.prototype.fixPrice = function (price) {
return price.base;
};
PriceCalculator.prototype.oneTimePrice = function (price, props) {
if (props.buyLicense) {
return this.fixPrice(price) + this.variablePrice(price, props) * 24;
else {
if (props.hardware) {
path += props.buyHardware ? '.buying' : '.leasing';
}
if (props.buyHardware) {
return this.fixPrice(price);
}
path += props.daily ? '.daily' : '.monthly';
}
var prices = _.get(prices_json_1.default, path, null);
return _.mapValues(prices, props.currency);
}
function variablePrice(prices, props) {
var variablePrice = prices.channel * props.channels + prices.listener * props.listeners;
return props.cloudStreaming && prices.cloudStreaming ? variablePrice + prices.cloudStreaming : variablePrice;
}
function fixPrice(prices) {
return prices.base;
}
function oneTimePrice(prices, props) {
if (props.buyLicense) {
return fixPrice(prices) + variablePrice(prices, props) * 24;
}
if (props.buyHardware) {
return fixPrice(prices);
}
return 0;
}
function periodicPrice(prices, props) {
if (props.buyLicense) {
return 0;
};
PriceCalculator.prototype.periodicPrice = function (price, props) {
if (props.buyLicense) {
return 0;
}
if (props.hardware && props.buyHardware) {
return this.variablePrice(price, props);
}
return this.fixPrice(price) + this.variablePrice(price, props);
};
PriceCalculator.prototype.loadPrices = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, axios_1.default
.get('https://preview.contentful.com/spaces/w513ekajli0x/environments/master/entries/f93leMrezgjLV1NGmXOVZ?access_token=4NyIH4qza6gjSQ7oA2-II2elNC9PLJDGSV05X7E8QVc')
.then(function (_a) {
var fields = _a.data.fields;
return fields.json;
})];
});
});
};
return PriceCalculator;
}());
exports.PriceCalculator = PriceCalculator;
var calculator = new PriceCalculator();
console.log(calculator.calculate(new CalculateProps()));
}
if (props.hardware && props.buyHardware) {
return variablePrice(prices, props);
}
return fixPrice(prices) + variablePrice(prices, props);
}
{
"name": "linkbox-price-service",
"version": "0.0.2",
"version": "0.0.3",
"description": "",

@@ -5,0 +5,0 @@ "main": "lib/price-calculator.js",

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