domain-quotes 0.0.20 → 0.1.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.
- package/README.md +2 -2
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -121,7 +121,7 @@ interface DomainPricesConfig {
|
|
|
121
121
|
restorePrices?: Record<string, number>;
|
|
122
122
|
transferPrices?: Record<string, number>;
|
|
123
123
|
exchangeRates: ExchangeRateData[]; // currency conversion data
|
|
124
|
-
|
|
124
|
+
vatRate: number; // single VAT rate applied to subtotal
|
|
125
125
|
discounts: Record<string, DiscountConfig>; // discount code → config
|
|
126
126
|
markup?: PriceMarkup; // optional markup applied before conversion
|
|
127
127
|
}
|
|
@@ -135,7 +135,7 @@ Errors
|
|
|
135
135
|
Notes
|
|
136
136
|
|
|
137
137
|
- Rounding is to 2 decimal places at each step to keep totals predictable (`base`, `discount`, `tax`, `total`).
|
|
138
|
-
- VAT
|
|
138
|
+
- A single VAT rate is applied to the subtotal by default (7.5% in the default config). Override `vatRate` in the config to change it.
|
|
139
139
|
- Price and exchange-rate data are fetched from maintained remote sources at import time:
|
|
140
140
|
- Prices: `https://raw.githubusercontent.com/namewiz/registrar-pricelist/refs/heads/main/data/unified-create-prices.csv`
|
|
141
141
|
- Exchange rates: `https://raw.githubusercontent.com/namewiz/registrar-pricelist/refs/heads/main/data/exchange-rates.json`
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var S={SAVE1:{rate:.01,extensions:["com","net"],startAt:"2023-01-01T00:00:00Z",endAt:"2025-12-31T23:59:59Z"},NEWUSER15:{rate:.15,extensions:["com","net","org"],startAt:"2023-01-01T00:00:00Z",endAt:"2024-12-31T23:59:59Z"},FALL20:{rate:.2,extensions:["org","info"],startAt:"2024-09-01T00:00:00Z",endAt:"2024-12-01T00:00:00Z"}};var U=.075;function I(){return(_.supportedCurrencies??["USD","NGN"]).slice()}function et(e){if(!e)return!1;let t=e.toUpperCase();return I().includes(t)}function nt(){let e=y();return Object.keys(e).sort()}function rt(e){let t=y(),n=A(e),r=t[n];return typeof r=="number"&&r>0}function A(e){return e&&e.trim().toLowerCase().replace(/^\.+/,"")}function $(e){return e instanceof Date?e.getTime():typeof e=="number"?e:Date.now()}var L="https://raw.githubusercontent.com/namewiz/registrar-pricelist/refs/heads/main/data/unified-create-prices.csv",M="https://raw.githubusercontent.com/namewiz/registrar-pricelist/refs/heads/main/data/exchange-rates.json";async function Z(e){let t=await fetch(e);if(!t.ok)throw new Error(`Failed to fetch ${e}: ${t.status} ${t.statusText}`);return t.text()}async function j(e){let t=await fetch(e);if(!t.ok)throw new Error(`Failed to fetch ${e}: ${t.status} ${t.statusText}`);return t.json()}function V(e){let t=e.split(/\r?\n/).map(i=>i.trim()).filter(Boolean);if(t.length===0)return{};let n=t.shift(),r={};for(let i of t){let g=i.split(",");if(g.length<3)continue;let u=g[0]?.trim().toLowerCase(),s=g[2]?.trim(),o=Number(s);!u||!Number.isFinite(o)||o<=0||(!(u in r)||o<r[u])&&(r[u]=o)}return r}var[z,J]=await Promise.all([Z(L).then(V),j(M)]);function y(){return z}function X(){return J}function H(){return S}var h=class extends Error{constructor(t,n){super(n),this.name="DomainPricesError",this.code=t}},R=class extends h{constructor(t){super("ERR_UNSUPPORTED_EXTENSION",`Unsupported extension: ${t}`),this.name="UnsupportedExtensionError"}},P=class extends h{constructor(t){super("ERR_UNSUPPORTED_CURRENCY",`Unsupported currency: ${t}`),this.name="UnsupportedCurrencyError"}};function q(){return{countryCode:"US",currencyName:"United States Dollar",currencySymbol:"$",currencyCode:"USD",exchangeRate:1,inverseRate:1}}function p(e){return Number(e.toFixed(2))}function B(e,t){if(!t)return e;let n=typeof t.value=="number"?t.value:0;if(!Number.isFinite(n)||n<=0)return e;switch(t.type){case"percentage":return e+e*n;case"fixedUsd":return e+n;default:return e}}var E=class{constructor(t){this.config=t}findRateInfo(t){if(t==="USD")return q();let n=this.config.exchangeRates.find(r=>r.currencyCode===t);if(!n)throw new P(t);return n}async getPrice(t,n,r={}){let i=this.config.createPrices,g=typeof this.config.vatRate=="number"?this.config.vatRate:U,u=this.config.discounts,s=A(t),o=r.transaction||"create",c;switch(o){case"renew":c=this.config.renewPrices?.[s]??i[s];break;case"restore":c=this.config.restorePrices?.[s]??i[s];break;case"transfer":c=this.config.transferPrices?.[s]??i[s];break;case"create":default:c=i[s];break}if(c===void 0||c===0)throw new R(s);let x=(n||"").toUpperCase();if(!(this.config.supportedCurrencies??["USD","NGN"]).includes(x))throw new P(n);let D=this.findRateInfo(x),k=D.currencySymbol,v=B(c,this.config.markup),d=p(v*D.exchangeRate),G=g,O=Array.from(new Set((r.discountCodes||[]).map(m=>m.toUpperCase()))),C=$(r.now),l=[];for(let m of O){let a=u[m];if(!a)continue;let w=Date.parse(a.startAt),N=Date.parse(a.endAt);Number.isNaN(w)||Number.isNaN(N)||C<w||C>N||a.extensions.includes(s)&&l.push(p(d*a.rate))}let f=0;l.length>0&&(r.discountPolicy==="stack"?f=p(l.reduce((m,a)=>m+a,0)):f=Math.max(...l)),f>d&&(f=d);let b=p(d-f),T=p(b*G),Q=p(b+T);return{extension:s,currency:x,basePrice:d,discount:f,tax:T,totalPrice:Q,symbol:k,transaction:o}}async getQuote(t,n,r={}){return this.getPrice(t,n,r)}},_={createPrices:y(),exchangeRates:X(),vatRate:U,discounts:H(),supportedCurrencies:["USD","NGN"]};async function W(e,t,n={}){return new E(_).getPrice(e,t,n)}async function st(e,t,n={}){return W(e,t,n)}export{_ as DEFAULT_CONFIG,U as DEFAULT_VAT_RATE,E as DomainPrices,E as DomainQuote,P as UnsupportedCurrencyError,R as UnsupportedExtensionError,W as getDefaultPrice,st as getDefaultQuote,et as isSupportedCurrency,rt as isSupportedExtension,I as listSupportedCurrencies,nt as listSupportedExtensions};
|