@balena/balena-pricing 0.2.0 → 0.3.0

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.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ !function(){"use strict";var e={};Object.defineProperty(e,"__esModule",{value:!0});var t=e.TypedError=void 0;let r;if(null!=Error.captureStackTrace){const e=Error.captureStackTrace;r=t=>{e(t,t.constructor)}}else r=(e,t)=>{t instanceof Error||(t=new Error(t)),null!=t.stack&&(e.stack=t.stack)};class s extends Error{constructor(e=""){super(),this.stack="",e instanceof Error?this.message=e.message:this.message=e,Object.setPrototypeOf(this,new.target.prototype),this.name=this.constructor.name,r(this,e)}}t=e.TypedError=s;class i extends t{constructor(e){super(e)}}const o={"device:microservices":{firstDiscountPriceCents:149,discountRate:.33,discountThreshold:12e3,discountThresholdPriceCents:125}};window.CreditPricing=class{constructor(e=o){this.credits=e}exists(e){return Object.keys(this.credits).includes(e)}getCreditPrice(e,t,r){if(!Number.isInteger(t))throw new i("Available credits must be a whole number");if(!Number.isInteger(r))throw new i("Credit purchase amount must be a whole number");if(t<0)throw new i("Available credits must be greater than or equal to 0");if(r<=0)throw new i("Credit purchase amount must be greater than 0");const s=function(e,t){const r=e[t];if(null==r)throw new i("Requested feature not allowed for credit usage");return r}(this.credits,e),o=t+r;if(0===r||0===o)return 0;if(o<=s.discountThreshold)return Math.round(s.firstDiscountPriceCents+(s.discountThresholdPriceCents-s.firstDiscountPriceCents)/(s.discountThreshold-1)*(o-1));const n=Math.round(s.discountThresholdPriceCents*Math.pow(1-s.discountRate,Math.log10(o/s.discountThreshold)));if(n<=0)throw new i("The provided quantity surpasses the maximum supported amount of credits");return n}getCreditTotalPrice(e,t,r){return Math.round(this.getCreditPrice(e,t,r)*r)}getDiscountOverDynamic(e,t,r,s){return Math.round((s-this.getCreditPrice(e,t,r))/s*100)}getTotalSavings(e,t,r,s){return Math.round(r*(s-this.getCreditPrice(e,t,r)))}}}();
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const index_1 = require("./index");
4
+ // Make it accessible on the window object
5
+ window.CreditPricing = index_1.CreditPricing;
6
+ //# sourceMappingURL=browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":";;AAAA,mCAAwC;AAExC,0CAA0C;AACzC,MAAc,CAAC,aAAa,GAAG,qBAAa,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const index_1 = require("./index");
4
+ // Make it accessible on the window object
5
+ window.CreditPricing = index_1.CreditPricing;
6
+ //# sourceMappingURL=browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.js","sourceRoot":"","sources":["../../src/browser.ts"],"names":[],"mappings":";;AAAA,mCAAwC;AAExC,0CAA0C;AACzC,MAAc,CAAC,aAAa,GAAG,qBAAa,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@balena/balena-pricing",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Balena pricing/savings calculators",
5
5
  "homepage": "https://github.com/balena-io-modules/balena-pricing#readme",
6
6
  "main": "dist",
@@ -11,7 +11,8 @@
11
11
  "pricing"
12
12
  ],
13
13
  "files": [
14
- "dist/"
14
+ "dist/",
15
+ "browser/"
15
16
  ],
16
17
  "license": "AGPL-3.0",
17
18
  "engines": {
@@ -32,11 +33,16 @@
32
33
  "test": "mocha",
33
34
  "posttest": "npm run lint",
34
35
  "prepare": "node -e \"try { require('husky').install() } catch (e) {if (e.code !== 'MODULE_NOT_FOUND') throw e}\" && tsc",
35
- "clean": "rimraf dist",
36
- "build": "npm run clean && tsc --project ./tsconfig.build.json"
36
+ "clean": "rimraf dist browser",
37
+ "build:browser": "rollup -c rollup.config.mjs",
38
+ "build:cjs": "tsc --project ./tsconfig.build.json",
39
+ "build": "npm run clean && npm run build:cjs && npm run build:browser"
37
40
  },
38
41
  "devDependencies": {
39
42
  "@balena/lint": "^6.2.1",
43
+ "@rollup/plugin-commonjs": "^24.0.1",
44
+ "@rollup/plugin-node-resolve": "^15.0.1",
45
+ "@rollup/plugin-terser": "^0.4.0",
40
46
  "@types/chai": "^4.3.4",
41
47
  "@types/mocha": "^10.0.1",
42
48
  "chai": "^4.3.7",
@@ -44,7 +50,9 @@
44
50
  "lint-staged": "^11.0.0",
45
51
  "mocha": "^8.4.0",
46
52
  "rimraf": "^4.0.4",
53
+ "rollup-plugin-ts": "^3.2.0",
47
54
  "ts-node": "^10.9.1",
55
+ "rollup": "^3.12.0",
48
56
  "typescript": "^4.9.4"
49
57
  },
50
58
  "lint-staged": {
@@ -59,7 +67,7 @@
59
67
  "_": "test/*.spec.ts"
60
68
  },
61
69
  "versionist": {
62
- "publishedAt": "2023-02-02T06:30:31.694Z"
70
+ "publishedAt": "2023-02-02T10:50:47.110Z"
63
71
  },
64
72
  "dependencies": {
65
73
  "typed-error": "^3.2.1"