npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mirai/services

v0.3.8

Published

Mirai API Services layer

Downloads

915

Readme

💾 @mirai/services

A naive isomorphic storage manager

📦 Setup

Add the package in your project:

yarn add @mirai/services

Configure the endpoints for each type of service

SERVICE_CURRENCY={{url}}
SERVICE_PRICING={{url}}

For development purpouses we will use .env file for this setup.

ServiceCountry

info(country)

Returns all the information available for a determinate country.

const country = await ServiceCountry.info('ES');
>> {
    "prefix": "93"
   }

list(locale)

Returns a map with the properties of each country.

const countries = await ServiceCountry.list('es-ES');
>> {
    "AF": { "prefix": "93" },
    "AL": { "prefix": "355" },
    "DZ": { "prefix": "213" },
    ...
  }

ℹ️ ServiceCountry has an auto-cache system that expires in 24 hours.

ServiceCurrency

convert(from , to, amount, reverse)

Convert the value from one currency to another

const conversion = ServiceCurrency.convert('USD', 'EUR', 10);
>> 10.08

exchange(currency)

Returns all the conversions rates for a determinate currency.

const rates = ServiceCurrency.exchange('USD');
>> {
     "AED": 4.06,
     "ARS": 121.31,
     "AUD": 1.5,
     ...
   }

ServiceDictionary

get()

Returns a dictionary of translations for a determinate locale.

const dictionary = ServiceDictionary.get('es-ES');

ServiceFeatures

initialize()

Initialize the service of "feature flag" downloading all rules from an endpoint.

const features = await ServiceFeatures.initialize();
>> {
     "occupation": false,
     "calendarPrices": true,
     "variants": {
       "00001": { "occupation": true },
       "00002": { "calendarPrices": false }
     }
   }

get(id, hotelId)

Returns a rule for a determinate hotel.

const hasOccupation = ServiceFeatures.get('occupation', '501404');
>> true

ServiceHotel

getCurrencies(id)

Returns for a given hotelId an object with the default currency per country.

const currencies = ServiceHotel.getCurrencies('501404');
>> {
     "AD": "EUR",
     "AR": "ARS",
     "AS": "USD",
     ...
   }

ServiceHotelVerse

getToken({ checkin, idHotel })

Returns for a given idHotel and checkin date the token for can communicate with Hotel Verse in case this is possible. If is not possible the function returns undefined

const accessTokenHv = ServiceHotelVerse.getToken({checkin:'01/05/2023', idHotel:'100376546'});
>> "YmxhIGJsYSBleGFtcGxl"

ServicePricing

get(id, from, months, currency)

Returns a list of prices sort by date and the hotel default currency.

const prices = ServicePricing.get('501404', '15/04/2022', 1, 'USD');
>> {
     "currency": "USD",
     "prices": {
       "22/04/2022": 216.00,
       "24/04/2022": 188.10,
       "25/04/2022": 180.00,
       ...
     }
   }

getStatic(id, from, months, userCurrency)

This method is a little bit tricky, because the last parameter userCurrency is optional. As the previous service (get) returns a list of prices sort by date, plus the hotel default currency and country.

const prices = ServicePricing.getStatic('501404', '15/04/2022', 1, 'USD');
>> {
     "country": "US",
     "currency": "USD",
     "prices": {
       "22/04/2022": 216.00,
       "24/04/2022": 188.10,
       "25/04/2022": 180.00,
       ...
     }
   }

ServiceUser

booking({ idHotel, env, lang, pinCode, reservationCode })

Get de token of a booking. All the params are mandatory. If exists an error related with the authentication, return a error with code 10. In other cases return a error with code 0

const response = await ServiceUser.booking({
  id: 55,
  idHotel: 1111,
  pinCode: 44
  });
>> {
     "token": "01F7D0EF7ED54F75DC79CAD00B46C116B31C687F"
   }

signup(properties)

⚠️ This method is pending of a refactor, because right now ask to many mandatory fields.

const session = await ServiceUser.signup({
  // country: 'ES',
  dateOfBirth: '10/04/1980',
  email: '[email protected]',
  firstName: 'javi',
  idClub: '6509887230248306646',
  idHotel: '501404',
  // language: 'es',
  lastName: 'jimenez',
  password: '12345678J',
  // privacy: true,
  // source: 'website',
  // subscribed: false,
}).catch((error) => {
  console.error(error);
});
>> true

login(username, password)

⚠️ This method is pending of a refactor, because right now is using oAuth protocol

const session = await ServiceUser.login(email, password).catch((error) => console.error(error));
>> {
      access_token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
      club_name: 'Garden Direct'
      email: '[email protected]',
      expires_in: 43199,
      first_name: 'j',
      id_club: 6509887230248307000,
      jti: 'a3b55543-b7c1-4aa5-a8b1-f97a1e15a082',
      last_name: 'j',
      refresh_token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
      scope: 'read',
      subscribed: false,
      token_type: 'bearer',
   }

resetPassword({ email, idClub, idHotel })

Resets the password of an active user, the new password will send by email.

const response = await ServiceUser.resetPassword({
  email: '[email protected]',
  idClub: 6509887230248307000,
  idHotel: '501404'
]);
>> {
     "result": "SUCCESS"
   }

signout()

Signout from the membership club.

const response = await ServiceUser.signout();
>> {
     joinedMembersConfirmationKeys: [593ZODOTrFIR_NRIvFssdP-PXZKCAbVnVvYZZkr_D98],
     result: SUCCESS
   }

⚠️ I think this method should return a boolean

logout()

Logout the current session.

const response = await ServiceUser.logout();
>> true

profile()

Returns the actual data of the user.

const profile = await ServiceUser.profile();
>> {
     idMember: 8973108064730172000,
     idClub: 6509887230248307000,
     email: '[email protected]',
     active: true,
     role: 'MEMBER',
     firstName: 'j',
     lastName: 'j',
     country: 'ES',
     language: 'es',
     joiningDate: '04/10/2022',
     source: 'WEBSITE',
     subscribed: false,
     dateOfBirth: '01/01/1960',
     extraFields: {},
     idJoinReservation: 0
  }

update({ firstname, lastname, dateOfBirth, country, subscribed })

Update some fields of the user.

const profile = await ServiceUser.update({
  firstName: 'javi',
  lastName: 'jimenez',
  dateOfBirth: '10/04/1980',
  country: 'TH',
  subscribed: true,
});
>> {
     "result": "SUCCESS"
   }

bookings()

Returns a list of bookings of the user.

const bookings = await ServiceUser.bookings();
>> [{
      hotelInfo: {
        name: 'Alcudia Garden Aparthotel ',
        address: 'Avinguda de la Platja, 1',
        location: 'Port d Alcúdia',
        province: 'Baleares',
        telephone: '+34 971 081 625',
        latitude: '39.842319',
        longitude: '3.1260377',
        countryIsoCode: 'ES',
        url: 'https://www.gardenhotels.com/alcudia-garden-aparthotel/',
        image: 'https://images.mirai.com/HOTEL_PHOTOS/100376538/NJVRSMFKMZFNMHYSVCYZ.jpg'
      },
      hotelCurrency: 'EUR',
      idTokenProvider: 100376538,
      idReservation: '20022077925',
      cancellationCode: 2258850,
      checkin: '08/10/2020',
      checkout: '10/10/2020',
      nights: 2,
      paymentDescription: 'Fizetés a létesítménybe való megérkezéskor. Bankkártya kizárólag a foglalás garanciájaként.',
      cancellationPolicySortText: 'Különleges feltételek: A lemondásnak költsége van',
      cancellationPolicy: 'CANCELLATION: Free up to 12:00 hours of the day okt.-06-2020. After that time, 20% of the total reservation will be charged on your card.',
      cancelDate: '20/02/2020'
    },
    ...
  ]