Skip to content

Commit 7488d08

Browse files
committed
Fix TypeError when entity-types API returns an object instead of array
The /entity-types endpoint returns a wrapped object (e.g. {data: [...]}) rather than a plain array. Normalize the response to an array when caching in both _buildEntityGroups and _buildShopData. https://claude.ai/code/session_01FcPMoRaH9FZsmU9JQ1eALo
1 parent 5242366 commit 7488d08

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

scripts/sync-dashboard.mjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,10 @@ export class SyncDashboard extends HandlebarsApplicationMixin(ApplicationV2) {
208208
async _buildEntityGroups(exclusions) {
209209
// Fetch entity types from Chronicle.
210210
if (!this._cache.entityTypes) {
211-
this._cache.entityTypes = await this.api.get('/entity-types');
211+
const raw = await this.api.get('/entity-types');
212+
this._cache.entityTypes = Array.isArray(raw) ? raw : (raw?.data || raw?.entity_types || []);
212213
}
213-
const types = this._cache.entityTypes || [];
214+
const types = this._cache.entityTypes;
214215

215216
// Fetch all entities (paginated, up to 500 for now).
216217
if (!this._cache.entities) {
@@ -395,9 +396,10 @@ export class SyncDashboard extends HandlebarsApplicationMixin(ApplicationV2) {
395396
async _buildShopData() {
396397
// Ensure entity types are cached.
397398
if (!this._cache.entityTypes) {
398-
this._cache.entityTypes = await this.api.get('/entity-types');
399+
const raw = await this.api.get('/entity-types');
400+
this._cache.entityTypes = Array.isArray(raw) ? raw : (raw?.data || raw?.entity_types || []);
399401
}
400-
const types = this._cache.entityTypes || [];
402+
const types = this._cache.entityTypes;
401403

402404
// Find the shop entity type by slug or name.
403405
const shopType = types.find(t =>

0 commit comments

Comments
 (0)