Switch from restaurant to vendor based selection

We are switching from restaurant to vendor based selection for the portal. For this change you need to update a little bit, as the token and the way you receive restaurant information changes.

Client side

Using the new token

On the client replace any createApi, createBatchApi or createMasterApi occurrence with the new createGlobalApi. The former three are deprecated in favour of the new global token. If you use the getAuth method, you should replace your current token with the globalToken from the getAuth() response.

Using the new Vendor selectors

Until now a user would select an/multiple RPS restaurant(s) from the restaurant selector. With the change to platform vendors we now introduced vendor selectors that work really similar.

Instead of the IRestaurantData object you will now have to handle with the IVendorData object, which has a similar interface:

export interface IVendorData {
  name: string;
  id: string;
  vendorId: string;
  globalEntityId: string;
  timezone: string;
  currency: IRestaurantCurrency;
  address: IRestaurantAddress;
}

The fields currency, address and timezone are the same as the restaurant equivalent. The id field content is a combined version of globalEntityId and vendorId divided by a semicolon:

Global Entity ID TB_KW and vendor ID 12345 will result in TB_KW;12345.

Instead of getCurrentRestaurant() you now need to use getCurrentVendor(). The same goes with getSelectedRestaurants() which will now be getSelectedVendors().

Also the restaurant observers have been deprecated and are replaced with addVendorObserver() and addSelectedVendorsObserver().

To use the vendor selectors you need to set your plugin config in your plugin's entry class:

import { RestaurantSelectorOptions, IPluginConfig } from '@deliveryhero/vendor-portal-sdk';

export default class HelloWorldPlugin {
  static getConfig(): IPluginConfig {
    return {
      restaurantSelector: RestaurantSelectorOptions.SINGLE_VENDOR,
    };
  }

  getMainComponent() {
    return App;
  }
}

Use RestaurantSelectorOptions.SINGLE_VENDOR for single vendor selection and RestaurantSelectorOptions.MULTIPLE_VENDORS if you support multiple selected vendors at a time.

React helpers

We also introduced react helpers (which include hooks and HoCs) to make it easier to work with the SDK inside react components. See more here.

Server side

The RPS ID will be removed from the token and platform vendorn information will be the main information in this token.

Vendors are grouped by globalEntityId, which allows putting more vendors into a single token.

{
  "country": "DE",
  "user": {
    "locale": "en",
    "name": "User Name",
    "email": "[email protected]"
  },
  "version": "1",
  "impersonator": false,
  "vendors": {
    "FO_NO": [
      "abc1",
      "x212"
    ],
    "FO_OP": [
      "4321",
    ],
  },
  "aud": "global",
  "sub": "{REGION}-{RUM_USER_ID}",
  ...
}

There are multiple things different:

  • sub now is a compliant with JWT specs and contains the region and user ID of the user to uniquely identify them.
  • Impersonation can now be detected by the impersonator property (was part of sub before).
  • RPS ID is gone
  • Vendors are now represented by a nested array
  • aud field for this token is global

If you need to check if a user has access to vendor a with the id x14b on FP_SG you need to do the following (example in JavaScript):

decodedToken.vendors.FP_SG.find(vendorId => vendorId === 'x14b')

results matching ""

    No results matching ""