code: public static Function<RequestEnvelope, String> deviceId() {
          return r -> Optional.ofNullable(r).map(RequestEnvelope::getContext)
                  .map(Context::getSystem)
                  .map(SystemState::getDevice)
                  .map(Device::getDeviceId)
                  .orElseThrow(() -> new PersistenceException("Could not retrieve device ID from request envelope to generate persistence ID"));
      }
docs: Produces a partition key from the device ID contained in an incoming request.
  @return partition key derived from device ID
  @throws PersistenceException if device ID cannot be retrieved