API Surgeon Scripts

Sometimes when extending JRNI, you want to be able to transform data either as it comes in or out of the system. This can be for features such as sanitising, validating or enhancing input data before it is passed into the platform, or it could be about changing response data, either by enhancing it, or altering things such as availability.

To serve this, JRNI has a feature called Surgeon scripts, which allow the adapting of inbound or outbound data

An example of a manifest of a inbound surgeon is:

  {
      "name":"ClientCreate",
      "description":"When a client is created",
      "type":"Surgeon",
      "actions": ["before_public_create_client"],
      "log_type": "None",
      "enabled": true,
      "handler": "before_public_create_client"
    }

These scripts are supported for a number of common APIs, although they are not supported on all API version (please note the minimum API versions)

Generally the surgeons are named:

(before/after)_(public/admin)_(create/update)_(api)

There are also version without admin/public that run on both endpoints

Inbound (before) surgeons

Inbound surgeons work on allowing you to change param data that is passed into the engine, either modify it, or reject it with an error.

To modify the data, return from your script:

callback(null, {status: "success", params: modified_params});

To reject the fall, return:

callback("Failed error message", {status: "error" });

The error message is then passed back in the response data from the API call

The data passed into the surgeons is:

  • params: The current params that were passed into the API call

Currently supported inbound surgeons are:

Surgeon ActionAPIVersion
before_public_create_clientPublic Create ClientV1-V5
before_public_update_clientPublic Update ClientV1-V5
before_admin_create_clientAdmin Create ClientV1-V5
before_admin_update_clientAdmin UpdateClientV1-V5
before_create_clientPublic and Admin Create ClientV1-V5
before_update_clientPublic and Admin Update ClientV1-V5
before_admin_create_bookingAdmin Booking CreateV1-V5
before_admin_update_bookingAdmin Booking UpdateV1-V5
purchase_update_bookingClient Purchase update BookingV1-V5
purchase_cancel_bookingClient Purchase Cancel BookingV1-V5

Outbound (after) surgeons

Outbound surgeons work bu letting you modify the returned data that is about to be sent back to the user

To modify the data, return from your script:

callback(null, {status: "success", params: modified_result});

To reject the fall, return:

callback("Failed surgeon result", {status: "error" });

In there surgeon javascript function is a data.params block which receives:

  • params: The parasm that were passed into the API call
  • headers: The key values of all headers that were passed in
  • api_response: The current API response that we are going to return
  • version: The API Version
  • context: The API permission context (i.e. admin.public etc..)

The current supported surgeons are:

Surgeon ActionAPIVersion
after_public_list_timesPublic List TimesV4
after_admin_list_timesAdmin List TimesV4
after_list_timesPublic and Admin List TimesV4