- 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
179 lines
4.2 KiB
JavaScript
Executable File
179 lines
4.2 KiB
JavaScript
Executable File
'use strict';
|
|
|
|
const Assert = require('@hapi/hoek/lib/assert');
|
|
const Clone = require('@hapi/hoek/lib/clone');
|
|
|
|
const Template = require('./template');
|
|
|
|
|
|
const internals = {};
|
|
|
|
|
|
exports.compile = function (messages, target) {
|
|
|
|
// Single value string ('plain error message', 'template {error} message')
|
|
|
|
if (typeof messages === 'string') {
|
|
Assert(!target, 'Cannot set single message string');
|
|
return new Template(messages);
|
|
}
|
|
|
|
// Single value template
|
|
|
|
if (Template.isTemplate(messages)) {
|
|
Assert(!target, 'Cannot set single message template');
|
|
return messages;
|
|
}
|
|
|
|
// By error code { 'number.min': <string | template> }
|
|
|
|
Assert(typeof messages === 'object' && !Array.isArray(messages), 'Invalid message options');
|
|
|
|
target = target ? Clone(target) : {};
|
|
|
|
for (let code in messages) {
|
|
const message = messages[code];
|
|
|
|
if (code === 'root' ||
|
|
Template.isTemplate(message)) {
|
|
|
|
target[code] = message;
|
|
continue;
|
|
}
|
|
|
|
if (typeof message === 'string') {
|
|
target[code] = new Template(message);
|
|
continue;
|
|
}
|
|
|
|
// By language { english: { 'number.min': <string | template> } }
|
|
|
|
Assert(typeof message === 'object' && !Array.isArray(message), 'Invalid message for', code);
|
|
|
|
const language = code;
|
|
target[language] = target[language] || {};
|
|
|
|
for (code in message) {
|
|
const localized = message[code];
|
|
|
|
if (code === 'root' ||
|
|
Template.isTemplate(localized)) {
|
|
|
|
target[language][code] = localized;
|
|
continue;
|
|
}
|
|
|
|
Assert(typeof localized === 'string', 'Invalid message for', code, 'in', language);
|
|
target[language][code] = new Template(localized);
|
|
}
|
|
}
|
|
|
|
return target;
|
|
};
|
|
|
|
|
|
exports.decompile = function (messages) {
|
|
|
|
// By error code { 'number.min': <string | template> }
|
|
|
|
const target = {};
|
|
for (let code in messages) {
|
|
const message = messages[code];
|
|
|
|
if (code === 'root') {
|
|
target.root = message;
|
|
continue;
|
|
}
|
|
|
|
if (Template.isTemplate(message)) {
|
|
target[code] = message.describe({ compact: true });
|
|
continue;
|
|
}
|
|
|
|
// By language { english: { 'number.min': <string | template> } }
|
|
|
|
const language = code;
|
|
target[language] = {};
|
|
|
|
for (code in message) {
|
|
const localized = message[code];
|
|
|
|
if (code === 'root') {
|
|
target[language].root = localized;
|
|
continue;
|
|
}
|
|
|
|
target[language][code] = localized.describe({ compact: true });
|
|
}
|
|
}
|
|
|
|
return target;
|
|
};
|
|
|
|
|
|
exports.merge = function (base, extended) {
|
|
|
|
if (!base) {
|
|
return exports.compile(extended);
|
|
}
|
|
|
|
if (!extended) {
|
|
return base;
|
|
}
|
|
|
|
// Single value string
|
|
|
|
if (typeof extended === 'string') {
|
|
return new Template(extended);
|
|
}
|
|
|
|
// Single value template
|
|
|
|
if (Template.isTemplate(extended)) {
|
|
return extended;
|
|
}
|
|
|
|
// By error code { 'number.min': <string | template> }
|
|
|
|
const target = Clone(base);
|
|
|
|
for (let code in extended) {
|
|
const message = extended[code];
|
|
|
|
if (code === 'root' ||
|
|
Template.isTemplate(message)) {
|
|
|
|
target[code] = message;
|
|
continue;
|
|
}
|
|
|
|
if (typeof message === 'string') {
|
|
target[code] = new Template(message);
|
|
continue;
|
|
}
|
|
|
|
// By language { english: { 'number.min': <string | template> } }
|
|
|
|
Assert(typeof message === 'object' && !Array.isArray(message), 'Invalid message for', code);
|
|
|
|
const language = code;
|
|
target[language] = target[language] || {};
|
|
|
|
for (code in message) {
|
|
const localized = message[code];
|
|
|
|
if (code === 'root' ||
|
|
Template.isTemplate(localized)) {
|
|
|
|
target[language][code] = localized;
|
|
continue;
|
|
}
|
|
|
|
Assert(typeof localized === 'string', 'Invalid message for', code, 'in', language);
|
|
target[language][code] = new Template(localized);
|
|
}
|
|
}
|
|
|
|
return target;
|
|
};
|