Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

strategy:
matrix:
node-version: [18.x] # Build on Node.js 18
node-version: [22.x] # Build on Node.js 22

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
printWidth: 190,
overrides: [
{
files: '*.{hbs,js,ts}',
files: '*.hbs',
options: {
singleQuote: false,
},
Expand Down
6 changes: 3 additions & 3 deletions addon/library/subject-custom-fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default class SubjectCustomFields {
this.setFieldValue(value, customField);

const fieldId = typeof customField === 'string' ? customField : customField?.id;
const valueType = typeof customField === 'string' ? null : customField?.valueType ?? customField?.value_type ?? null;
const valueType = typeof customField === 'string' ? null : (customField?.valueType ?? customField?.value_type ?? null);
if (!fieldId || !resource) return;

let rec = this.#getLocalValueRecord(resource, fieldId);
Expand All @@ -91,7 +91,7 @@ export default class SubjectCustomFields {
let { value_type } = entry;
if (!value_type) {
const cf = this.store.peekRecord?.('custom-field', fieldId);
value_type = cf ? cf.valueType ?? cf.value_type ?? null : null;
value_type = cf ? (cf.valueType ?? cf.value_type ?? null) : null;
}
next[fieldId] = { value, value_type };
}
Expand Down Expand Up @@ -253,7 +253,7 @@ export default class SubjectCustomFields {
}

// Normalize to array
const existing = isArray(existingMany) ? existingMany : existingMany?.toArray?.() ?? [];
const existing = isArray(existingMany) ? existingMany : (existingMany?.toArray?.() ?? []);

const byFieldId = new Map();
for (let i = 0; i < existing.length; i++) {
Expand Down
8 changes: 6 additions & 2 deletions addon/services/current-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { isBlank } from '@ember/utils';
import { alias } from '@ember/object/computed';
import { storageFor } from 'ember-local-storage';
import { debug } from '@ember/debug';
import lookupUserIp from '../utils/lookup-user-ip';
import lookupUserIp, { getBrowserTimezone } from '../utils/lookup-user-ip';

/**
* CurrentUserService
Expand Down Expand Up @@ -84,6 +84,10 @@ export default class CurrentUserService extends Service.extend(Evented) {
return this.whois('country_code');
}

get timezone() {
return this.whois('timezone') || getBrowserTimezone();
}

async load() {
if (this.session.isAuthenticated) {
const user = await this.store.findRecord('user', 'me');
Expand Down Expand Up @@ -180,7 +184,7 @@ export default class CurrentUserService extends Service.extend(Evented) {
const fallback = {
city: null,
country_code: null,
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
timezone: getBrowserTimezone(),
_source: 'fallback',
};

Expand Down
2 changes: 2 additions & 0 deletions addon/utils/load-installed-extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export default async function loadInstalledExtensions(additionalCoreEngines = []
'@fleetbase/iam-engine',
'@fleetbase/ledger-engine',
'@fleetbase/pallet-engine',
'@fleetbase/vroom-engine',
'@fleetbase/valhalla-engine',
...additionalCoreEngines,
];
const INDEXED_ENGINES = await loadExtensions();
Expand Down
35 changes: 29 additions & 6 deletions addon/utils/lookup-user-ip.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@ export default async function lookupUserIp(options = {}) {

const data = await response.json();
const normalized = api.normalize(data);
const normalizedWithTimezone = ensureWhoisTimezone(normalized);

// Cache the result if enabled
if (cache) {
cacheWhois(normalized);
cacheWhois(normalizedWithTimezone);
}

return normalized;
return normalizedWithTimezone;
} catch (error) {
console.warn(`[lookupUserIp] ${api.url} failed:`, error.message);
// Continue to next API
Expand All @@ -92,7 +93,7 @@ function normalizeGeoIPLookup(data) {
latitude: data.latitude,
longitude: data.longitude,
postal_code: data.postal_code,
timezone: data.timezone_name,
timezone: data.timezone_name || getBrowserTimezone(),
currency: {
code: data.currency_code,
name: data.currency_name,
Expand Down Expand Up @@ -128,7 +129,7 @@ function normalizeIPApi(data) {
latitude: data.latitude,
longitude: data.longitude,
postal_code: data.postal,
timezone: data.timezone,
timezone: data.timezone || getBrowserTimezone(),
currency: {
code: data.currency,
name: data.currency_name,
Expand Down Expand Up @@ -163,7 +164,12 @@ function getCachedWhois() {
return null;
}

return data;
const normalized = ensureWhoisTimezone(data);
if (normalized.timezone !== data.timezone) {
cacheWhois(normalized);
}

return normalized;
} catch (error) {
console.error('[getCachedWhois] Error reading cache:', error);
return null;
Expand All @@ -187,7 +193,7 @@ function cacheWhois(data) {
function getFallbackWhois() {
// Try to get browser language and timezone as fallback
const browserLang = navigator.language || 'en-US';
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
const timezone = getBrowserTimezone();

return {
ip: null,
Expand Down Expand Up @@ -219,3 +225,20 @@ function getFallbackWhois() {
_timestamp: Date.now(),
};
}

export function getBrowserTimezone() {
try {
return Intl.DateTimeFormat().resolvedOptions().timeZone || null;
} catch (error) {
return null;
}
}

export function ensureWhoisTimezone(whois = {}) {
whois = whois || {};

return {
...whois,
timezone: whois.timezone || getBrowserTimezone(),
};
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fleetbase/ember-core",
"version": "0.3.18",
"version": "0.3.19",
"description": "Provides all the core services, decorators and utilities for building a Fleetbase extension for the Console.",
"keywords": [
"fleetbase-core",
Expand Down
Loading
Loading