0.2.146 • Published 9 months ago

@mirai/services v0.2.146

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
9 months ago

💾 @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: 'mirai@soyjavi.com',
  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: 'mirai@soyjavi.com',
      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: 'mirai@soyjavi.com',
  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: 'mirai@soyjavi.com',
     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'
    },
    ...
  ]
0.2.146

9 months ago

0.2.145

9 months ago

0.2.144

10 months ago

0.2.143

10 months ago

0.2.142

10 months ago

0.2.141

11 months ago

0.2.140

1 year ago

0.2.139

1 year ago

0.2.138

1 year ago

0.2.137

1 year ago

0.2.136

1 year ago

0.2.135

1 year ago

0.2.134

1 year ago

0.2.133

1 year ago

0.2.132

1 year ago

0.2.131

1 year ago

0.2.130

1 year ago

0.2.129

1 year ago

0.2.128

1 year ago

0.2.127

1 year ago

0.2.126

1 year ago

0.2.125

1 year ago

0.2.124

1 year ago

0.2.123

1 year ago

0.2.122

1 year ago

0.2.121

1 year ago

0.2.120

1 year ago

0.2.118-patch

2 years ago

0.2.119

2 years ago

0.2.118

2 years ago

0.2.117

2 years ago

0.2.116

2 years ago

0.2.115

2 years ago

0.2.114

2 years ago

0.2.113

2 years ago

0.2.112

2 years ago

0.2.111

2 years ago

0.2.110

2 years ago

0.2.96

2 years ago

0.2.95

2 years ago

0.2.94

2 years ago

0.2.93

2 years ago

0.2.92

2 years ago

0.2.91

2 years ago

0.2.90

2 years ago

0.2.99

2 years ago

0.2.98

2 years ago

0.2.97

2 years ago

0.2.85

2 years ago

0.2.84

2 years ago

0.2.83

2 years ago

0.2.82

2 years ago

0.2.81

2 years ago

0.2.80

2 years ago

0.2.89

2 years ago

0.2.88

2 years ago

0.2.87

2 years ago

0.2.86

2 years ago

0.2.74

2 years ago

0.2.73

2 years ago

0.2.72

2 years ago

0.2.71

2 years ago

0.2.70

2 years ago

0.2.79

2 years ago

0.2.78

2 years ago

0.2.77

2 years ago

0.2.76

2 years ago

0.2.75

2 years ago

0.2.109

2 years ago

0.2.108

2 years ago

0.2.63

2 years ago

0.2.107

2 years ago

0.2.62

2 years ago

0.2.106

2 years ago

0.2.105

2 years ago

0.2.104

2 years ago

0.2.103

2 years ago

0.2.102

2 years ago

0.2.101

2 years ago

0.2.100

2 years ago

0.2.61-beta

2 years ago

0.2.68

2 years ago

0.2.67

2 years ago

0.2.66

2 years ago

0.2.65

2 years ago

0.2.61

2 years ago

0.2.56-beta

2 years ago

0.2.60

2 years ago

0.2.52

2 years ago

0.2.51

2 years ago

0.2.50

2 years ago

0.2.59

2 years ago

0.2.58

2 years ago

0.2.57

2 years ago

0.2.56

2 years ago

0.2.55

2 years ago

0.2.54

2 years ago

0.2.53

2 years ago

0.2.41

2 years ago

0.2.40

2 years ago

0.2.49

2 years ago

0.2.48

2 years ago

0.2.47

2 years ago

0.2.46

2 years ago

0.2.45

2 years ago

0.2.44

2 years ago

0.2.43

2 years ago

0.2.42

2 years ago

0.2.39

2 years ago

0.2.38

2 years ago

0.2.37

2 years ago

0.2.36

2 years ago

0.2.35

2 years ago

0.2.34

2 years ago

0.2.33

2 years ago

0.2.27

2 years ago

0.2.30

2 years ago

0.2.32

2 years ago

0.2.31

2 years ago

0.2.29

2 years ago

0.2.28

2 years ago

0.2.26

2 years ago

0.2.25

2 years ago

0.2.24

2 years ago

0.2.23

2 years ago

0.2.22

3 years ago

0.2.21

3 years ago

0.2.20

3 years ago

0.2.19

3 years ago

0.2.18

3 years ago

0.2.17

3 years ago

0.2.16

3 years ago

0.2.15

3 years ago

0.2.14

3 years ago

0.2.13

3 years ago

0.2.12

3 years ago

0.2.11

3 years ago

0.2.10

3 years ago

0.2.7

3 years ago

0.2.6

3 years ago

0.2.9

3 years ago

0.2.8

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.1.14

3 years ago

0.2.1

3 years ago

0.2.0-b

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.1.10

3 years ago

0.1.11

3 years ago

0.1.12

3 years ago

0.1.13

3 years ago

0.1.2

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.9

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago