20.1.2 • Published 4 months ago

@karhoo/demand-deeplink v20.1.2

Weekly downloads
367
License
BSD-2-Clause
Repository
github
Last release
4 months ago

Karhoo Deeplink is a method of passing the user’s required information from the Demand Partner’s side to a Karhoo web booking application.

This library is intended to be the standard way of working with a deeplink.

Read The Docs

License

Installation

npm i @karhoo/demand-deeplink

Warnings

This library uses URLSearchParams. For old browsers, e.g. IE11 you must bring your own polyfill. You can use either js-core@3 or url-search-params-polyfill(version 8 and above)

This library uses Promise. For old browsers, e.g. IE11 you must bring your own polyfill. You can use js-core@3 to polyfill Promise

Usage

import { parse, validate, generate, Deeplink } from '@karhoo/demand-deeplink'

Parse deeplink:

const deeplinkData = parse(window.location.search)

Validate deeplink:

const { ok, errors } = validate(deeplinkData)

Generate deeplink:

const queryString = generate(deeplinkData)

Resolve deeplink:

To use Deeplink class api parameter (see Api type here) should be passed as a second argument of Deeplink constructor. For this purposes @karhoo/demand-api can be used.

import { getApi } from '@karhoo/demand-api'

const api = getApi()

const subscriber = data => console.log(data)

const deeplink = new Deeplink(window.location.search, api)

deeplink.resolve(subscriber)

Example

A lot of deeplink examples can be find here

Let's imagine, you want to deeplink from a hotel booking website to a Karhoo cab booking website.

Your customer booked a hotel room and reached their booking confirmation page. From here you can offer a complementary service to book a cab to a hotel's location.

At this stage, you know:

  1. Hotel address
  2. Time when a cab required (based on hotel check-in hours)
  3. Number of passengers
  4. Passenger first and last name (if you're willing to pass it)

All these parameters can be embedded to a Deeplink and passed to a Karhoo booking app.

Step 1. Compose deeplink data

const deeplinkData = {
  legs: [
    {
      dropoff: 'Hotel Ermitage, London, UK',
      pickupTime: '2020-03-12T12:00:00+01:00',
    },
  ],
  passengerInfo: {
    passengers: 3,
    firstName: 'Jon',
  },
  bookingType: 'PRE-BOOK',
  meta: {},
}

Step 2. Validate deeplink data

import { validate } from '@karhoo/demand-deeplink'

const { ok, errors } = validate(deeplinkData)

if (!ok) {
  console.log('Deeplink data is invalid', errors)
}

Step 3. Generate a deeplink

import { validate, generate } from '@karhoo/demand-deeplink'

const { ok, errors } = validate(deeplinkData)

if (!ok) {
  console.log('Deeplink data is invalid', errors)
  return
}

const deeplink = generate(deeplinkData)
console.log(deeplink) // ?leg-1-dropoff=Hotel+Ermitage%2C+London%2C+UK&leg-1-pickup-time=2020-03-12T12%3A00%3A00%2B01%3A00&passengers=3&first-name=Jon&booking-type=PRE-BOOK

When you get a deeplink you can navigate your user from your website by adding the link to href attribute.

For example, <a target="_blank" href="https://your-branded-app.kathoo.com/landing/?leg-1-dropoff=Hotel+Ermitage%2C+London%2C+UK&leg-1-pickup-time=2020-03-12T12%3A00%3A00%2B01%3A00&passengers=3&first-name=Jon&booking-type=PRE-BOOK"> Book a cab to a hotel </a>

Issues

Looking to contribute?

🐛 Bugs

Please file an issue for bugs, missing documentation, or unexpected behavior with a label DEEPLINK

💡 Feature Requests

Please file an issue to suggest new features with a label DEEPLINK. Vote on feature requests by adding a 👍. This helps maintainers prioritize what to work on.

❓ Questions

For questions related to using the library, please re-visit a documentation first. If there are no answer, please create an issue with a label help needed and DEEPLINK.

Contributing

License

BSD-2-Clause

20.1.2

4 months ago

20.1.1

4 months ago

20.1.0

4 months ago

20.0.0

5 months ago

19.1.1

1 year ago

19.0.1

1 year ago

19.0.0

1 year ago

19.1.0

1 year ago

18.2.1

1 year ago

18.2.0

1 year ago

17.13.1

1 year ago

18.1.0

1 year ago

18.0.0

1 year ago

17.12.0

2 years ago

17.13.0

2 years ago

17.10.0

2 years ago

17.9.2

2 years ago

17.11.0

2 years ago

17.9.1

2 years ago

17.7.0

2 years ago

17.8.0

2 years ago

17.5.5

2 years ago

17.9.0

2 years ago

17.6.0

2 years ago

17.5.2

2 years ago

17.5.4

2 years ago

17.5.3

2 years ago

17.3.0

2 years ago

17.4.0

2 years ago

17.0.1

2 years ago

17.5.0

2 years ago

17.5.1

2 years ago

17.2.0

2 years ago

17.0.0

2 years ago

16.15.0

2 years ago

16.15.1

2 years ago

16.14.0

2 years ago

16.13.0

2 years ago

16.16.0

2 years ago

16.9.0

2 years ago

16.11.0

2 years ago

16.10.0

2 years ago

16.8.0

2 years ago

16.12.0

2 years ago

16.7.0

3 years ago

16.6.1

3 years ago

16.6.0

3 years ago

16.5.0

3 years ago

16.4.0

3 years ago

16.3.0

3 years ago

16.2.0

3 years ago

16.1.4

3 years ago

16.1.3

3 years ago

16.1.2

3 years ago

16.1.1

3 years ago

16.1.0

3 years ago

16.0.1

3 years ago

15.2.2

3 years ago

16.0.0

3 years ago

15.2.1

3 years ago

15.2.0

3 years ago

15.1.0

3 years ago

15.0.1

3 years ago

15.0.0

3 years ago

14.0.1

3 years ago

14.0.0

3 years ago

13.0.2

3 years ago

13.0.1

3 years ago

13.0.0

3 years ago

12.0.0

3 years ago

11.8.0

3 years ago

11.7.0

3 years ago

11.6.0

3 years ago

11.5.3

3 years ago

11.5.2

3 years ago

11.5.1

3 years ago

11.5.0

3 years ago

11.4.0

3 years ago

11.3.0

3 years ago

11.2.0

3 years ago

11.1.1

3 years ago

11.1.0

3 years ago

11.0.1

3 years ago

11.0.0

3 years ago

10.7.0

3 years ago

10.6.1

3 years ago

10.6.0

3 years ago

10.5.0

3 years ago

10.4.0

3 years ago

10.3.1

4 years ago

10.3.0

4 years ago

10.2.0

4 years ago

10.1.0

4 years ago

10.0.1

4 years ago

10.0.0

4 years ago

9.1.0

4 years ago

9.0.0

4 years ago

8.7.0

4 years ago

8.6.0

4 years ago

8.5.0

4 years ago

8.4.0

4 years ago

8.3.0

4 years ago

8.2.0

4 years ago

8.1.0

4 years ago

8.0.0

4 years ago

7.2.0

4 years ago

7.1.0

4 years ago

7.0.0

4 years ago

6.4.0

4 years ago

6.3.0

4 years ago

6.2.0

4 years ago

6.1.0

4 years ago

6.0.0

4 years ago

5.0.0

4 years ago

4.1.0

4 years ago

4.0.0

4 years ago

3.0.0

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.0

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.11.0

4 years ago

0.10.2

4 years ago

0.10.1

4 years ago

0.10.0

4 years ago

0.9.2

4 years ago

0.9.1

4 years ago

0.9.0

4 years ago

0.8.2

4 years ago

0.8.1

4 years ago

0.7.2

4 years ago

0.6.0

4 years ago

0.5.0

4 years ago