domain-quotes 0.0.10 → 0.0.11

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/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ var k={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 v={US:0,GB:.2,DE:.19,NG:.075};var b={USD:"US",GBP:"GB",EUR:"DE",NGN:"NG"};function se(){return Object.keys(b)}function oe(t){return t!=null&&b.hasOwnProperty(t.toUpperCase())}function ie(){let t=E();return Object.keys(t).sort()}function ce(t){let e=E(),r=O(e,t),n=e[r];return typeof n=="number"&&n>0}function O(t,e){if(!e)return e;let n=e.trim().toLowerCase().replace(/^\.+/,"");if(!n)return"";if(t.hasOwnProperty(n))return n;if(n.includes(".")){let s=n.split(".");for(let i=0;i<s.length;i++){let c=s.slice(i).join(".");if(t.hasOwnProperty(c))return c}return s[s.length-1]}return n}function j(t){return t instanceof Date?t.getTime():typeof t=="number"?t:Date.now()}var F="https://raw.githubusercontent.com/namewiz/registrar-pricelist/refs/heads/main/data/unified-create-prices.csv",L="https://raw.githubusercontent.com/namewiz/registrar-pricelist/refs/heads/main/data/exchange-rates.json";async function Z(t){let e=await fetch(t);if(!e.ok)throw new Error(`Failed to fetch ${t}: ${e.status} ${e.statusText}`);return e.text()}async function B(t){let e=await fetch(t);if(!e.ok)throw new Error(`Failed to fetch ${t}: ${e.status} ${e.statusText}`);return e.json()}function J(t){let e=t.split(/\r?\n/).map(s=>s.trim()).filter(Boolean);if(e.length===0)return{};let r=e.shift(),n={};for(let s of e){let i=s.split(",");if(i.length<3)continue;let c=i[0]?.trim().toLowerCase(),o=i[2]?.trim(),a=Number(o);!c||!Number.isFinite(a)||a<=0||(!(c in n)||a<n[c])&&(n[c]=a)}return n}var[z,Q]=await Promise.all([Z(F).then(J),B(L)]);function E(){return z}function X(){return Q}function H(){return v}function q(){return k}var x=class extends Error{constructor(e,r){super(r),this.name="DomainPricesError",this.code=e}},y=class extends x{constructor(e){super("ERR_UNSUPPORTED_EXTENSION",`Unsupported extension: ${e}`),this.name="UnsupportedExtensionError"}},l=class extends x{constructor(e){super("ERR_UNSUPPORTED_CURRENCY",`Unsupported currency: ${e}`),this.name="UnsupportedCurrencyError"}};function W(){return{countryCode:"US",currencyName:"United States Dollar",currencySymbol:"$",currencyCode:"USD",exchangeRate:1,inverseRate:1}}function p(t){return Math.round(t*100)/100}function Y(t,e){if(!e)return t;let r=typeof e.value=="number"?e.value:0;if(!Number.isFinite(r)||r<=0)return t;switch(e.type){case"percentage":return t+t*r;case"fixedUsd":return t+r;default:return t}}var P=class{constructor(e){this.config=e}findRateInfo(e){if(e==="USD")return W();let r=this.config.exchangeRates.find(n=>n.currencyCode===e);if(!r)throw new l(e);return r}async getPrice(e,r,n={}){let s=this.config.createPrices,i=this.config.vatRates,c=this.config.discounts,o=O(s,e),a=n.transaction||"create",u;switch(a){case"renew":u=this.config.renewPrices?.[o]??s[o];break;case"restore":u=this.config.restorePrices?.[o]??s[o];break;case"transfer":u=this.config.transferPrices?.[o]??s[o];break;case"create":default:u=s[o];break}if(u===void 0||u===0)throw new y(o);let R=(r||"").toUpperCase(),w=b[R];if(!w)throw new l(r);let D=i[w];if(typeof D!="number")throw new l(r);let C=this.findRateInfo(R),_=C.currencySymbol,G=Y(u,this.config.markup),d=p(G*C.exchangeRate),I=Array.from(new Set((n.discountCodes||[]).map(m=>m.toUpperCase()))),T=j(n.now),h=[];for(let m of I){let f=c[m];if(!f)continue;let U=Date.parse(f.startAt),A=Date.parse(f.endAt);Number.isNaN(U)||Number.isNaN(A)||T<U||T>A||f.extensions.includes(o)&&h.push(p(d*f.rate))}let g=0;h.length>0&&(n.discountPolicy==="stack"?g=p(h.reduce((m,f)=>m+f,0)):g=Math.max(...h)),g>d&&(g=d);let S=p(d-g),N=p(S*D),M=p(S+N);return{extension:o,currency:R,basePrice:d,discount:g,tax:N,totalPrice:M,symbol:_,transaction:a}}},K={createPrices:E(),exchangeRates:X(),vatRates:H(),discounts:q()};async function ae(t,e,r={}){return new P(K).getPrice(t,e,r)}export{K as DEFAULTS_Sept2025,P as DomainPrices,l as UnsupportedCurrencyError,y as UnsupportedExtensionError,ae as getDefaultPrice,oe as isSupportedCurrency,ce as isSupportedExtension,se as listSupportedCurrencies,ie as listSupportedExtensions};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "domain-quotes",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "Fast multi-currency domain price checker library across registrars.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/todo.txt DELETED
@@ -1,5 +0,0 @@
1
-
2
- "comment": "organizational email constraint, origin website, max # of years, whether it can be combined with other coupons, user country code, new customer only",
3
- "comment2": "doesn't support fixed amount intentionally, avoid -ve charges, ",
4
- "comment3": "each code can be used an unlimited number of times between start and end",
5
- "comment4": "Alt: enable use:once or use:once_per_user",