- App.tsx: full navigation (Auth stack + Main tabs with 5 screens) - Auth: LoginScreen, RegisterScreen, ForgotPasswordScreen - HomeScreen: dashboard with IoT metrics, weather widget, alerts, quick actions, sensors - MapScreen: interactive map with layer toggles (6 layers) - MarketplaceScreen: categories (6), products (5), search - ChatScreen: AI chat with quick prompts (4), bot responses - ProfileScreen: user info, stats, menu (9 items), logout - AlertsScreen: alert list with severity, acknowledge - SensorsScreen: sensor list with type filters (6 types), search - ZonesScreen: zone cards with stats - SettingsScreen: language picker (FR/EN/ES/DE), privacy, about - Stores: iotStore (sensors, zones, alerts), notificationStore, uiStore + i18n - Hooks: useSensors, useAlerts, useNotifications, useLocation - Components: Card, Button, LoadingSpinner, ErrorBoundary, Header - Services: iotService, notificationService (with axios API client) - Utils: formatters (temp, AQI, noise, dates), validators (email, password, IBAN) - Theme: colors.ts with full design system (Blue Ocean palette) - Ditto: fixed MongoDB connection, new JWT secrets, official gateway image
88 lines
2.4 KiB
C++
88 lines
2.4 KiB
C++
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#include "MethodCall.h"
|
|
|
|
#include <folly/json.h>
|
|
#include <stdexcept>
|
|
|
|
namespace facebook::react {
|
|
|
|
#define REQUEST_MODULE_IDS 0
|
|
#define REQUEST_METHOD_IDS 1
|
|
#define REQUEST_PARAMS 2
|
|
#define REQUEST_CALLID 3
|
|
|
|
static const char* errorPrefix = "Malformed calls from JS: ";
|
|
|
|
std::vector<MethodCall> parseMethodCalls(folly::dynamic&& jsonData) {
|
|
if (jsonData.isNull()) {
|
|
return {};
|
|
}
|
|
|
|
if (!jsonData.isArray()) {
|
|
throw std::invalid_argument(folly::to<std::string>(
|
|
errorPrefix, "input isn't array but ", jsonData.typeName()));
|
|
}
|
|
|
|
if (jsonData.size() < REQUEST_PARAMS + 1) {
|
|
throw std::invalid_argument(
|
|
folly::to<std::string>(errorPrefix, "size == ", jsonData.size()));
|
|
}
|
|
|
|
auto& moduleIds = jsonData[REQUEST_MODULE_IDS];
|
|
auto& methodIds = jsonData[REQUEST_METHOD_IDS];
|
|
auto& params = jsonData[REQUEST_PARAMS];
|
|
int callId = -1;
|
|
|
|
if (!moduleIds.isArray() || !methodIds.isArray() || !params.isArray()) {
|
|
throw std::invalid_argument(folly::to<std::string>(
|
|
errorPrefix,
|
|
"not all fields are arrays.\n\n",
|
|
folly::toJson(jsonData)));
|
|
}
|
|
|
|
if (moduleIds.size() != methodIds.size() ||
|
|
moduleIds.size() != params.size()) {
|
|
throw std::invalid_argument(folly::to<std::string>(
|
|
errorPrefix,
|
|
"field sizes are different.\n\n",
|
|
folly::toJson(jsonData)));
|
|
}
|
|
|
|
if (jsonData.size() > REQUEST_CALLID) {
|
|
if (!jsonData[REQUEST_CALLID].isNumber()) {
|
|
throw std::invalid_argument(folly::to<std::string>(
|
|
errorPrefix, "invalid callId", jsonData[REQUEST_CALLID].typeName()));
|
|
}
|
|
callId = (int)jsonData[REQUEST_CALLID].asInt();
|
|
}
|
|
|
|
std::vector<MethodCall> methodCalls;
|
|
for (size_t i = 0; i < moduleIds.size(); i++) {
|
|
if (!params[i].isArray()) {
|
|
throw std::invalid_argument(folly::to<std::string>(
|
|
errorPrefix,
|
|
"method arguments isn't array but ",
|
|
params[i].typeName()));
|
|
}
|
|
|
|
methodCalls.emplace_back(
|
|
static_cast<int>(moduleIds[i].asInt()),
|
|
static_cast<int>(methodIds[i].asInt()),
|
|
std::move(params[i]),
|
|
callId);
|
|
|
|
// only increment callid if contains valid callid as callid is optional
|
|
callId += (callId != -1) ? 1 : 0;
|
|
}
|
|
|
|
return methodCalls;
|
|
}
|
|
|
|
} // namespace facebook::react
|