@mapvx/web-js 3.6.0-dev.1 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/README.md +6 -1
  2. package/dist/cjs/index.js +2 -95
  3. package/dist/cjs/index.js.LICENSE.txt +1 -0
  4. package/dist/cjs/index.js.map +1 -1
  5. package/dist/es/controllers/routeController.d.ts.map +1 -1
  6. package/dist/es/controllers/routeController.js +25 -8
  7. package/dist/es/controllers/routeController.js.map +1 -1
  8. package/dist/es/logger/sentry.js +1 -1
  9. package/dist/es/map/liveMapFitTransform.d.ts +11 -5
  10. package/dist/es/map/liveMapFitTransform.d.ts.map +1 -1
  11. package/dist/es/map/liveMapFitTransform.js +28 -19
  12. package/dist/es/map/liveMapFitTransform.js.map +1 -1
  13. package/dist/es/map/map.d.ts.map +1 -1
  14. package/dist/es/map/map.js +3 -6
  15. package/dist/es/map/map.js.map +1 -1
  16. package/dist/umd/index.js +932 -126
  17. package/dist/umd/index.js.map +1 -1
  18. package/dist/umd/styles.css +1 -1
  19. package/dist/umd/styles.css.map +1 -1
  20. package/package.json +7 -4
  21. package/dist/cjs/assets/icons.js +0 -85
  22. package/dist/cjs/assets/icons.js.map +0 -1
  23. package/dist/cjs/config/draco.js +0 -15
  24. package/dist/cjs/config/draco.js.map +0 -1
  25. package/dist/cjs/config/sdkConfig.js +0 -3
  26. package/dist/cjs/config/sdkConfig.js.map +0 -1
  27. package/dist/cjs/controllers/markerLayoutController.js +0 -359
  28. package/dist/cjs/controllers/markerLayoutController.js.map +0 -1
  29. package/dist/cjs/controllers/routeController.js +0 -1549
  30. package/dist/cjs/controllers/routeController.js.map +0 -1
  31. package/dist/cjs/domain/models/_internal.js +0 -14
  32. package/dist/cjs/domain/models/_internal.js.map +0 -1
  33. package/dist/cjs/domain/models/_rtl.js +0 -10
  34. package/dist/cjs/domain/models/_rtl.js.map +0 -1
  35. package/dist/cjs/domain/models/animation.js +0 -64
  36. package/dist/cjs/domain/models/animation.js.map +0 -1
  37. package/dist/cjs/domain/models/banner.js +0 -24
  38. package/dist/cjs/domain/models/banner.js.map +0 -1
  39. package/dist/cjs/domain/models/campaign.js +0 -73
  40. package/dist/cjs/domain/models/campaign.js.map +0 -1
  41. package/dist/cjs/domain/models/categories.js +0 -37
  42. package/dist/cjs/domain/models/categories.js.map +0 -1
  43. package/dist/cjs/domain/models/circle.js +0 -253
  44. package/dist/cjs/domain/models/circle.js.map +0 -1
  45. package/dist/cjs/domain/models/cityFilterOption.js +0 -3
  46. package/dist/cjs/domain/models/cityFilterOption.js.map +0 -1
  47. package/dist/cjs/domain/models/configuration.js +0 -3
  48. package/dist/cjs/domain/models/configuration.js.map +0 -1
  49. package/dist/cjs/domain/models/cssCustomization.js +0 -3
  50. package/dist/cjs/domain/models/cssCustomization.js.map +0 -1
  51. package/dist/cjs/domain/models/fitOptions.js +0 -3
  52. package/dist/cjs/domain/models/fitOptions.js.map +0 -1
  53. package/dist/cjs/domain/models/innerFloors.js +0 -3
  54. package/dist/cjs/domain/models/innerFloors.js.map +0 -1
  55. package/dist/cjs/domain/models/institution.js +0 -45
  56. package/dist/cjs/domain/models/institution.js.map +0 -1
  57. package/dist/cjs/domain/models/latLng.js +0 -3
  58. package/dist/cjs/domain/models/latLng.js.map +0 -1
  59. package/dist/cjs/domain/models/location.js +0 -3
  60. package/dist/cjs/domain/models/location.js.map +0 -1
  61. package/dist/cjs/domain/models/loggeable.js +0 -52
  62. package/dist/cjs/domain/models/loggeable.js.map +0 -1
  63. package/dist/cjs/domain/models/mapCamera.js +0 -3
  64. package/dist/cjs/domain/models/mapCamera.js.map +0 -1
  65. package/dist/cjs/domain/models/mapConfig.js +0 -37
  66. package/dist/cjs/domain/models/mapConfig.js.map +0 -1
  67. package/dist/cjs/domain/models/marker.js +0 -502
  68. package/dist/cjs/domain/models/marker.js.map +0 -1
  69. package/dist/cjs/domain/models/multilanguage.js +0 -17
  70. package/dist/cjs/domain/models/multilanguage.js.map +0 -1
  71. package/dist/cjs/domain/models/openingHours.js +0 -3
  72. package/dist/cjs/domain/models/openingHours.js.map +0 -1
  73. package/dist/cjs/domain/models/place.js +0 -127
  74. package/dist/cjs/domain/models/place.js.map +0 -1
  75. package/dist/cjs/domain/models/platform.js +0 -3
  76. package/dist/cjs/domain/models/platform.js.map +0 -1
  77. package/dist/cjs/domain/models/popover.js +0 -3
  78. package/dist/cjs/domain/models/popover.js.map +0 -1
  79. package/dist/cjs/domain/models/product.js +0 -3
  80. package/dist/cjs/domain/models/product.js.map +0 -1
  81. package/dist/cjs/domain/models/property.js +0 -104
  82. package/dist/cjs/domain/models/property.js.map +0 -1
  83. package/dist/cjs/domain/models/route.js +0 -166
  84. package/dist/cjs/domain/models/route.js.map +0 -1
  85. package/dist/cjs/domain/models/routeConfiguration.js +0 -82
  86. package/dist/cjs/domain/models/routeConfiguration.js.map +0 -1
  87. package/dist/cjs/domain/models/routeInstance.js +0 -30
  88. package/dist/cjs/domain/models/routeInstance.js.map +0 -1
  89. package/dist/cjs/domain/models/routeStyle.js +0 -3
  90. package/dist/cjs/domain/models/routeStyle.js.map +0 -1
  91. package/dist/cjs/domain/models/scene3D.js +0 -3
  92. package/dist/cjs/domain/models/scene3D.js.map +0 -1
  93. package/dist/cjs/domain/models/transport.js +0 -22
  94. package/dist/cjs/domain/models/transport.js.map +0 -1
  95. package/dist/cjs/domain/ports/ICache.js +0 -3
  96. package/dist/cjs/domain/ports/ICache.js.map +0 -1
  97. package/dist/cjs/domain/ports/IHttpClient.js +0 -3
  98. package/dist/cjs/domain/ports/IHttpClient.js.map +0 -1
  99. package/dist/cjs/domain/ports/ILogger.js +0 -23
  100. package/dist/cjs/domain/ports/ILogger.js.map +0 -1
  101. package/dist/cjs/domain/ports/index.js +0 -10
  102. package/dist/cjs/domain/ports/index.js.map +0 -1
  103. package/dist/cjs/infrastructure/cache/CacheManager.js +0 -258
  104. package/dist/cjs/infrastructure/cache/CacheManager.js.map +0 -1
  105. package/dist/cjs/infrastructure/cache/LRUCache.js +0 -153
  106. package/dist/cjs/infrastructure/cache/LRUCache.js.map +0 -1
  107. package/dist/cjs/infrastructure/cache/PersistentCache.js +0 -168
  108. package/dist/cjs/infrastructure/cache/PersistentCache.js.map +0 -1
  109. package/dist/cjs/infrastructure/cache/cacheConfig.js +0 -70
  110. package/dist/cjs/infrastructure/cache/cacheConfig.js.map +0 -1
  111. package/dist/cjs/infrastructure/http/FetchHttpClient.js +0 -75
  112. package/dist/cjs/infrastructure/http/FetchHttpClient.js.map +0 -1
  113. package/dist/cjs/infrastructure/logging/MVXLogger.js +0 -80
  114. package/dist/cjs/infrastructure/logging/MVXLogger.js.map +0 -1
  115. package/dist/cjs/interfaces/cache.js +0 -3
  116. package/dist/cjs/interfaces/cache.js.map +0 -1
  117. package/dist/cjs/interfaces/healthResponse.js +0 -3
  118. package/dist/cjs/interfaces/healthResponse.js.map +0 -1
  119. package/dist/cjs/interfaces/institutionResponse.js +0 -3
  120. package/dist/cjs/interfaces/institutionResponse.js.map +0 -1
  121. package/dist/cjs/interfaces/metadata.js +0 -3
  122. package/dist/cjs/interfaces/metadata.js.map +0 -1
  123. package/dist/cjs/interfaces/placeResponse.js +0 -3
  124. package/dist/cjs/interfaces/placeResponse.js.map +0 -1
  125. package/dist/cjs/interfaces/routeCacheResponse.js +0 -3
  126. package/dist/cjs/interfaces/routeCacheResponse.js.map +0 -1
  127. package/dist/cjs/interfaces/routeResponse.js +0 -3
  128. package/dist/cjs/interfaces/routeResponse.js.map +0 -1
  129. package/dist/cjs/interfaces/styleResponse.js +0 -3
  130. package/dist/cjs/interfaces/styleResponse.js.map +0 -1
  131. package/dist/cjs/logger/logger.js +0 -78
  132. package/dist/cjs/logger/logger.js.map +0 -1
  133. package/dist/cjs/logger/sentry.js +0 -81
  134. package/dist/cjs/logger/sentry.js.map +0 -1
  135. package/dist/cjs/map/fitCamera.js +0 -124
  136. package/dist/cjs/map/fitCamera.js.map +0 -1
  137. package/dist/cjs/map/liveMapFitTransform.js +0 -180
  138. package/dist/cjs/map/liveMapFitTransform.js.map +0 -1
  139. package/dist/cjs/map/map.js +0 -2766
  140. package/dist/cjs/map/map.js.map +0 -1
  141. package/dist/cjs/map/mapInteractionOptions.js +0 -73
  142. package/dist/cjs/map/mapInteractionOptions.js.map +0 -1
  143. package/dist/cjs/map/scene3DController.js +0 -849
  144. package/dist/cjs/map/scene3DController.js.map +0 -1
  145. package/dist/cjs/repository/repository.js +0 -694
  146. package/dist/cjs/repository/repository.js.map +0 -1
  147. package/dist/cjs/repository/requester.js +0 -771
  148. package/dist/cjs/repository/requester.js.map +0 -1
  149. package/dist/cjs/sdk.js +0 -438
  150. package/dist/cjs/sdk.js.map +0 -1
  151. package/dist/cjs/utils/3d.js +0 -245
  152. package/dist/cjs/utils/3d.js.map +0 -1
  153. package/dist/cjs/utils/deckLayers.js +0 -153
  154. package/dist/cjs/utils/deckLayers.js.map +0 -1
  155. package/dist/cjs/utils/error.js +0 -19
  156. package/dist/cjs/utils/error.js.map +0 -1
  157. package/dist/cjs/utils/images.js +0 -25
  158. package/dist/cjs/utils/images.js.map +0 -1
  159. package/dist/cjs/utils/loadGlb.js +0 -190
  160. package/dist/cjs/utils/loadGlb.js.map +0 -1
  161. package/dist/cjs/utils/mapvxHostname.js +0 -21
  162. package/dist/cjs/utils/mapvxHostname.js.map +0 -1
  163. package/dist/cjs/utils/nav-functions.js +0 -150
  164. package/dist/cjs/utils/nav-functions.js.map +0 -1
  165. package/dist/cjs/utils/opening-hours-helper.js +0 -914
  166. package/dist/cjs/utils/opening-hours-helper.js.map +0 -1
  167. package/dist/cjs/utils/preconnect.js +0 -131
  168. package/dist/cjs/utils/preconnect.js.map +0 -1
  169. package/dist/cjs/utils/route-utils.js +0 -57
  170. package/dist/cjs/utils/route-utils.js.map +0 -1
  171. package/dist/cjs/utils/semaphore.js +0 -143
  172. package/dist/cjs/utils/semaphore.js.map +0 -1
  173. package/dist/cjs/utils/three.js +0 -113
  174. package/dist/cjs/utils/three.js.map +0 -1
  175. package/dist/cjs/utils/threeScene.js +0 -126
  176. package/dist/cjs/utils/threeScene.js.map +0 -1
  177. package/dist/cjs/utils/update-css.js +0 -76
  178. package/dist/cjs/utils/update-css.js.map +0 -1
  179. package/dist/cjs/utils/utils.js +0 -104
  180. package/dist/cjs/utils/utils.js.map +0 -1
@@ -1,694 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Repository = void 0;
4
- const campaign_1 = require("../domain/models/campaign");
5
- const institution_1 = require("../domain/models/institution");
6
- const loggeable_1 = require("../domain/models/loggeable");
7
- const place_1 = require("../domain/models/place");
8
- const route_1 = require("../domain/models/route");
9
- const transport_1 = require("../domain/models/transport");
10
- const CacheManager_1 = require("../infrastructure/cache/CacheManager");
11
- const requester_1 = require("./requester");
12
- /**
13
- * Extracts a human-readable error message from an API error response body.
14
- * Handles various response formats: string, object with message/error field, or falls back to JSON.
15
- * @param errorBody - The parsed JSON body from an error response
16
- * @returns A string representation of the error
17
- * @hidden
18
- */
19
- function extractErrorMessage(errorBody) {
20
- if (typeof errorBody === "string")
21
- return errorBody;
22
- if (errorBody && typeof errorBody === "object") {
23
- const obj = errorBody;
24
- if (typeof obj.message === "string")
25
- return obj.message;
26
- if (typeof obj.error === "string")
27
- return obj.error;
28
- }
29
- return JSON.stringify(errorBody);
30
- }
31
- /**
32
- * Represents the repository for the SDK.
33
- * @hidden
34
- */
35
- class Repository extends loggeable_1.Loggeable {
36
- constructor(token, lang, apiUrl, cache, mapvxRequestContext, endpoints) {
37
- super();
38
- this.currentLang = "en";
39
- this.token = token;
40
- this.currentLang = lang;
41
- this.requester = new requester_1.Requester(lang, apiUrl, mapvxRequestContext, endpoints);
42
- this.cache = cache !== null && cache !== void 0 ? cache : new CacheManager_1.CacheManager();
43
- }
44
- /**
45
- * function to change the lang of requests
46
- * @param lang request response language
47
- */
48
- setLang(lang) {
49
- this.currentLang = lang;
50
- this.requester.setLang(lang);
51
- }
52
- prepareSegmentation(segmentation) {
53
- return Object.assign(Object.assign({}, segmentation), { token: this.token });
54
- }
55
- async fetchAndParseMapStyle(placeId, styleRef, styleTheme) {
56
- // `baseStyle` caches only the default (no place, no explicit preview ref/theme).
57
- const cacheable = placeId === undefined && styleRef === undefined && styleTheme === undefined;
58
- if (cacheable && this.baseStyle) {
59
- return this.baseStyle;
60
- }
61
- try {
62
- const response = await this.requester.fetchMapStyle(this.token, placeId, styleRef, styleTheme);
63
- if (!response.ok) {
64
- const errorBody = await response.json();
65
- throw new Error(`Fetch failed with status ${response.status}: ${extractErrorMessage(errorBody)}`);
66
- }
67
- const responseData = (await response.json());
68
- const style = responseData.style;
69
- if (cacheable) {
70
- this.baseStyle = style;
71
- }
72
- this.logEvent("fetchAndParseMapStyle");
73
- return style;
74
- }
75
- catch (error) {
76
- this.logError(error, { functionName: "fetchAndParseMapStyle" });
77
- throw new Error("Failed to fetch and parse map style", { cause: error });
78
- }
79
- }
80
- /**
81
- * Bearer-authenticated style fetch: resolves a style by explicit ref/theme for
82
- * a place through the bearer map style endpoint, authorized by the user's
83
- * client access instead of the api key's scopes. Mirrors
84
- * {@link fetchAndParseMapStyle} but with a user bearer token.
85
- */
86
- async fetchAndParseMapStyleByBearer(placeId, authToken, styleRef, styleTheme) {
87
- try {
88
- const response = await this.requester.fetchMapStyleByBearer(authToken, placeId, styleRef, styleTheme);
89
- if (!response.ok) {
90
- const errorBody = await response.json();
91
- throw new Error(`Fetch failed with status ${response.status}: ${extractErrorMessage(errorBody)}`);
92
- }
93
- const responseData = (await response.json());
94
- const style = responseData.style;
95
- this.logEvent("fetchAndParseMapStyleByBearer");
96
- return style;
97
- }
98
- catch (error) {
99
- this.logError(error, { functionName: "fetchAndParseMapStyleByBearer" });
100
- throw new Error("Failed to fetch and parse map style with bearer token", {
101
- cause: error,
102
- });
103
- }
104
- }
105
- async fetchAndParseAnyMapStyle(institutionId, authToken) {
106
- try {
107
- const response = await this.requester.fetchAnyMapStyle(authToken, institutionId);
108
- if (!response.ok) {
109
- const errorBody = await response.json();
110
- throw new Error(`Fetch failed with status ${response.status}: ${extractErrorMessage(errorBody)}`);
111
- }
112
- const responseData = (await response.json());
113
- const style = responseData.style;
114
- this.logEvent("fetchAndParseAnyMapStyle");
115
- return style;
116
- }
117
- catch (error) {
118
- this.logError(error, { functionName: "fetchAndParseAnyMapStyle" });
119
- throw new Error("Failed to fetch and parse map style with bearer token", { cause: error });
120
- }
121
- }
122
- async fetchAndParseInstitutions() {
123
- try {
124
- const response = await this.requester.fetchInstitutions(this.token);
125
- if (!response.ok) {
126
- const errorBody = await response.json();
127
- throw new Error(`Fetch failed with status ${response.status}: ${extractErrorMessage(errorBody)}`);
128
- }
129
- const responseData = (await response.json());
130
- const institutions = [];
131
- for (const institutionData of responseData) {
132
- const institution = new institution_1.Institution(institutionData);
133
- institutions.push(institution);
134
- }
135
- institutions.sort((a, b) => a.title.localeCompare(b.title));
136
- const resultInstitution = institutions;
137
- if (resultInstitution) {
138
- this.logEvent("fetchAndParseInstitutionsV2");
139
- return resultInstitution;
140
- }
141
- else {
142
- throw new Error("No institutions associated to this apiKey");
143
- }
144
- }
145
- catch (error) {
146
- this.logError(error, { functionName: "fetchAndParseInstitutionsV2" });
147
- throw new Error("Failed to fetch and parse institution", { cause: error });
148
- }
149
- }
150
- async fetchAndParsePlaceDetail(query) {
151
- try {
152
- const { id, buildingId, floorId, level } = query;
153
- const cacheKey = this.placeCacheKey(id, buildingId);
154
- const cachedPlace = this.cache.getPlace(cacheKey, this.currentLang);
155
- if (cachedPlace != null) {
156
- this.logEvent("fetchAndParsePlaceDetail", { cached: "true" });
157
- return cachedPlace;
158
- }
159
- const response = await this.requester.fetchPlaceDetail(this.token, id, buildingId, floorId, level);
160
- if (!response.ok) {
161
- const errorBody = await response.json();
162
- throw new Error(`Fetch failed with status ${response.status}: ${extractErrorMessage(errorBody)}`);
163
- }
164
- const responseData = (await response.json());
165
- const place = new place_1.MVXPlace(responseData);
166
- this.cachePlace(place, buildingId);
167
- this.logEvent("fetchAndParsePlaceDetail", { cached: "false" });
168
- return place;
169
- }
170
- catch (error) {
171
- throw new Error("Failed to fetch and parse place detail", { cause: error });
172
- }
173
- }
174
- async fetchAndParseAnyPlaceDetail(query, authToken) {
175
- try {
176
- const { id, buildingId, floorId, level } = query;
177
- const cacheKey = this.placeCacheKey(id, buildingId);
178
- const cachedPlace = this.cache.getPlace(cacheKey, this.currentLang);
179
- if (cachedPlace != null) {
180
- this.logEvent("fetchAndParseAnyPlaceDetail", { cached: "true" });
181
- return cachedPlace;
182
- }
183
- const response = await this.requester.fetchAnyPlaceDetail(authToken, id, buildingId, floorId, level);
184
- if (!response.ok) {
185
- const errorBody = await response.json();
186
- throw new Error(`Fetch failed with status ${response.status}: ${extractErrorMessage(errorBody)}`);
187
- }
188
- const responseData = (await response.json());
189
- const place = new place_1.MVXPlace(responseData);
190
- this.cachePlace(place, buildingId);
191
- this.logEvent("fetchAndParseAnyPlaceDetail", { cached: "false" });
192
- return place;
193
- }
194
- catch (error) {
195
- throw new Error("Failed to fetch and parse place detail with bearer token", { cause: error });
196
- }
197
- }
198
- /**
199
- * Build the cache key for a place lookup. The canonical `mapvxId` is globally
200
- * unique, but integrator aliases (`clientId`) may be reused across buildings, so
201
- * alias-based keys are namespaced by `buildingId` to prevent aliases from
202
- * different venues from colliding in the cache.
203
- */
204
- placeCacheKey(id, buildingId) {
205
- return buildingId != null ? `${id}_${buildingId}` : id;
206
- }
207
- /**
208
- * Cache a place under its globally-unique `mapvxId` and, when present, under its
209
- * (possibly non-unique) `clientId` alias namespaced by `buildingId`.
210
- */
211
- cachePlace(place, buildingId) {
212
- this.cache.setPlace(place.mapvxId, place, this.currentLang);
213
- if (place.clientId != null) {
214
- this.cache.setPlace(this.placeCacheKey(place.clientId, buildingId), place, this.currentLang);
215
- }
216
- }
217
- async fetchAndParseSubPlaces(parentPlaceId) {
218
- try {
219
- // Check cache first
220
- const cachedSubPlaces = this.cache.getSubPlaces(parentPlaceId, this.currentLang);
221
- if (cachedSubPlaces != null) {
222
- this.logEvent("fetchAndParseSubPlaces", { cached: "true" });
223
- return cachedSubPlaces.data;
224
- }
225
- const response = await this.requester.fetchSubPlaces(parentPlaceId, this.token);
226
- if (!response.ok) {
227
- const errorBody = await response.json();
228
- throw new Error(`Fetch failed with status ${response.status}: ${extractErrorMessage(errorBody)}`);
229
- }
230
- const responseData = (await response.json());
231
- const subPlaces = responseData.map((place) => new place_1.MVXPlace(place));
232
- // Cache the result
233
- this.cache.setSubPlaces(parentPlaceId, this.currentLang, {
234
- timestamp: Date.now(),
235
- data: subPlaces,
236
- });
237
- this.logEvent("fetchAndParseSubPlaces", { cached: "false" });
238
- subPlaces.forEach((place) => {
239
- if (!this.cache.hasPlace(place.mapvxId, this.currentLang)) {
240
- this.cache.setPlace(place.mapvxId, place, this.currentLang);
241
- }
242
- if (place.clientId != null && !this.cache.hasPlace(place.clientId, this.currentLang)) {
243
- this.cache.setPlace(place.clientId, place, this.currentLang);
244
- }
245
- });
246
- return subPlaces;
247
- }
248
- catch (error) {
249
- throw new Error("Failed to fetch and parse subplaces", { cause: error });
250
- }
251
- }
252
- async fetchAndParseAnySubPlaces(parentPlaceId, authToken) {
253
- try {
254
- const response = await this.requester.fetchAnySubPlaces(parentPlaceId, authToken);
255
- if (!response.ok) {
256
- const errorBody = await response.json();
257
- throw new Error(`Fetch failed with status ${response.status}: ${extractErrorMessage(errorBody)}`);
258
- }
259
- const responseData = (await response.json());
260
- const subPlaces = responseData.map((place) => new place_1.MVXPlace(place));
261
- this.logEvent("fetchAndParseAnySubPlaces");
262
- subPlaces.forEach((place) => {
263
- if (!this.cache.hasPlace(place.mapvxId, this.currentLang)) {
264
- this.cache.setPlace(place.mapvxId, place, this.currentLang);
265
- }
266
- if (place.clientId != null && !this.cache.hasPlace(place.clientId, this.currentLang)) {
267
- this.cache.setPlace(place.clientId, place, this.currentLang);
268
- }
269
- });
270
- return subPlaces;
271
- }
272
- catch (error) {
273
- throw new Error("Failed to fetch and parse any subplaces", { cause: error });
274
- }
275
- }
276
- async fetchAndParseAvailablePlaces() {
277
- try {
278
- const response = await this.requester.fetchAllowedPlaces(this.token);
279
- if (!response.ok) {
280
- const errorBody = await response.json();
281
- throw new Error(`Fetch failed with status ${response.status}: ${extractErrorMessage(errorBody)}`);
282
- }
283
- const typedResponseData = (await response.json());
284
- const data = typedResponseData.map((data) => {
285
- return new place_1.MVXPlace(data);
286
- });
287
- this.logEvent("fetchAndParseAvailablePlaces");
288
- data.forEach((place) => {
289
- if (!this.cache.hasPlace(place.mapvxId, this.currentLang)) {
290
- this.cache.setPlace(place.mapvxId, place, this.currentLang);
291
- }
292
- if (place.clientId != null && !this.cache.hasPlace(place.clientId, this.currentLang)) {
293
- this.cache.setPlace(place.clientId, place, this.currentLang);
294
- }
295
- });
296
- return data;
297
- }
298
- catch (error) {
299
- this.logError(error, { functionName: "fetchAndParseAvailablePlaces" });
300
- throw new Error("Failed to fetch and parse parent places", { cause: error });
301
- }
302
- }
303
- async fetchAndParsePlacesFromInstitution(institutionId, authToken) {
304
- try {
305
- const response = await this.requester.fetchPlacesFromAnyInstitution(institutionId, authToken);
306
- if (!response.ok) {
307
- const errorBody = await response.json();
308
- throw new Error(`Fetch failed with status ${response.status}: ${extractErrorMessage(errorBody)}`);
309
- }
310
- const typedResponseData = (await response.json());
311
- const data = typedResponseData.map((data) => {
312
- return new place_1.MVXPlace(data);
313
- });
314
- this.logEvent("fetchAndParsePlacesFromInstitution");
315
- data.forEach((place) => {
316
- if (!this.cache.hasPlace(place.mapvxId, this.currentLang)) {
317
- this.cache.setPlace(place.mapvxId, place, this.currentLang);
318
- }
319
- if (place.clientId != null && !this.cache.hasPlace(place.clientId, this.currentLang)) {
320
- this.cache.setPlace(place.clientId, place, this.currentLang);
321
- }
322
- });
323
- return data;
324
- }
325
- catch (error) {
326
- this.logError(error, {
327
- functionName: "fetchAndParsePlacesFromInstitution",
328
- });
329
- throw new Error("Failed to fetch and parse parent places from institution", { cause: error });
330
- }
331
- }
332
- getCachedPlaces(ids) {
333
- const places = [];
334
- ids.forEach((id) => {
335
- const place = this.cache.getPlace(id, this.currentLang);
336
- if (place != null) {
337
- places.push(place);
338
- }
339
- });
340
- return places;
341
- }
342
- /**
343
- * Get cached subplaces for a parent place without making additional requests.
344
- * @param parentPlaceId The parent place identifier
345
- * @returns Array of cached subplaces or undefined if not cached
346
- */
347
- getCachedSubPlaces(parentPlaceId) {
348
- const cachedSubPlaces = this.cache.getSubPlaces(parentPlaceId, this.currentLang);
349
- return cachedSubPlaces === null || cachedSubPlaces === void 0 ? void 0 : cachedSubPlaces.data;
350
- }
351
- async fetchAndParseRoute(config) {
352
- try {
353
- let destinationId = "";
354
- if ("id" in config.finalLocation) {
355
- destinationId = config.finalLocation.id;
356
- }
357
- const cachedResponse = this.cache.getRoute(destinationId);
358
- if (cachedResponse != null) {
359
- this.logEvent("fetchAndParseRoute", { cached: "true" });
360
- this.debugLog("Route cache testing. Found in caché.");
361
- return cachedResponse.data;
362
- }
363
- const response = await this.requester.fetchRoute(config, this.token);
364
- if (!response.ok) {
365
- const errorBody = await response.json();
366
- throw new Error(`Fetch failed with status ${response.status}: ${extractErrorMessage(errorBody)}`);
367
- }
368
- const responseData = (await response.json());
369
- const route = new route_1.MVXRoute(responseData[0]);
370
- this.logEvent("fetchAndParseRoute");
371
- this.debugLog("Route cache testing. Fetched.");
372
- return route;
373
- }
374
- catch (error) {
375
- throw new Error("Failed to fetch and parse route", { cause: error });
376
- }
377
- }
378
- async fetchAndParseRouteV2(config) {
379
- try {
380
- let destinationId = "";
381
- if ("id" in config.finalLocation) {
382
- destinationId = config.finalLocation.id;
383
- }
384
- const cachedResponse = this.cache.getRoute(destinationId);
385
- if (cachedResponse != null) {
386
- this.logEvent("fetchAndParseRouteV2", { cached: "true" });
387
- this.debugLog("Route cache testing. Found in caché.");
388
- return cachedResponse.data;
389
- }
390
- const response = await this.requester.fetchRouteV2(config, this.token);
391
- if (!response.ok) {
392
- const errorBody = await response.json();
393
- throw new Error(`Fetch failed with status ${response.status}: ${extractErrorMessage(errorBody)}`);
394
- }
395
- const responseData = (await response.json());
396
- const route = new route_1.MVXRoute(responseData[0]);
397
- this.logEvent("fetchAndParseRouteV2");
398
- this.debugLog("Route cache testing. Fetched.");
399
- return route;
400
- }
401
- catch (error) {
402
- throw new Error("Failed to fetch and parse route", { cause: error });
403
- }
404
- }
405
- async fetchAndParseLiveRoute(config) {
406
- try {
407
- // Live routes are always fetched fresh (no cache read) so a moving user
408
- // gets an up-to-date path rather than a previously cached one.
409
- const response = await this.requester.fetchLiveRoute(config, this.token);
410
- if (!response.ok) {
411
- const errorBody = await response.json();
412
- throw new Error(`Fetch failed with status ${response.status}: ${extractErrorMessage(errorBody)}`);
413
- }
414
- const responseData = (await response.json());
415
- const route = new route_1.MVXRoute(responseData[0]);
416
- this.logEvent("fetchAndParseLiveRoute");
417
- this.debugLog("Live route fetched.");
418
- return route;
419
- }
420
- catch (error) {
421
- throw new Error("Failed to fetch and parse route", { cause: error });
422
- }
423
- }
424
- async fetchAndParseTransport(stopId) {
425
- try {
426
- const cachedResponse = this.cache.getVehicle(stopId, this.currentLang);
427
- if (cachedResponse != null &&
428
- (Date.now() - cachedResponse.timestamp < 60 * 1000 ||
429
- cachedResponse.data.routes.length === 0)) {
430
- this.logEvent("fetchAndParseTransport", { cached: "true" });
431
- return cachedResponse.data;
432
- }
433
- const response = await this.requester.fetchTransport(this.token, stopId);
434
- if (!response.ok) {
435
- const errorBody = await response.json();
436
- throw new Error(`Fetch failed with status ${response.status}: ${extractErrorMessage(errorBody)}`);
437
- }
438
- const typedResponseData = (await response.json());
439
- if (typedResponseData.realtimeSchedules.length > 0) {
440
- const stopsPromises = typedResponseData.realtimeSchedules.map((e) => this.fetchAndParseStops(stopId, e.vehicleId));
441
- const stops = await Promise.all(stopsPromises);
442
- if (stops.length > 0) {
443
- typedResponseData.realtimeSchedules.forEach((vehicle) => {
444
- var _a, _b;
445
- vehicle.stops = (_b = (_a = stops.find((e) => e.id == vehicle.vehicleId)) === null || _a === void 0 ? void 0 : _a.places) !== null && _b !== void 0 ? _b : [];
446
- });
447
- }
448
- }
449
- const transport = new transport_1.MVXTransport(typedResponseData);
450
- this.cache.setVehicle(stopId, {
451
- timestamp: Date.now(),
452
- data: transport,
453
- }, this.currentLang);
454
- this.logEvent("fetchAndParseTransport", { cached: "false" });
455
- return transport;
456
- }
457
- catch (error) {
458
- const cachedResponse = this.cache.getVehicle(stopId, this.currentLang);
459
- if (cachedResponse != null) {
460
- const transport = new transport_1.MVXTransport({
461
- realtimeSchedules: [],
462
- schedules: cachedResponse.data.schedule,
463
- });
464
- this.logEvent("fetchAndParseTransport", { cached: "true" });
465
- return transport;
466
- }
467
- else {
468
- throw new Error("Failed to fetch and parse transport", { cause: error });
469
- }
470
- }
471
- }
472
- async fetchAndParseStops(stopId, vehicleId) {
473
- try {
474
- const cachedResponse = this.cache.getStops(stopId + vehicleId, this.currentLang);
475
- if (cachedResponse != null && Date.now() - cachedResponse.timestamp < 60 * 1000) {
476
- this.logEvent("fetchAndParseStops", { cached: "true" });
477
- return { id: vehicleId, places: cachedResponse.data };
478
- }
479
- const response = await this.requester.fetchStops(this.token, stopId, vehicleId);
480
- if (!response.ok) {
481
- const errorBody = await response.json();
482
- throw new Error(`Fetch failed with status ${response.status}: ${extractErrorMessage(errorBody)}`);
483
- }
484
- const typedResponseData = (await response.json());
485
- const data = typedResponseData.map((e) => {
486
- return new place_1.MVXPlace(e);
487
- });
488
- this.cache.setStops(stopId + vehicleId, { timestamp: Date.now(), data }, this.currentLang);
489
- this.logEvent("fetchAndParseStops", { cached: "false" });
490
- return { id: vehicleId, places: data };
491
- }
492
- catch (error) {
493
- throw new Error("Failed to fetch and parse stops", { cause: error });
494
- }
495
- }
496
- async fetchAndParseSearchResults(institutionId, input, parentPlaces, origin, lat, lng, floor) {
497
- try {
498
- const response = await this.requester.fetchSearchResults(institutionId, input, this.token, parentPlaces, origin, lat, lng, floor);
499
- if (!response.ok) {
500
- const errorBody = await response.json();
501
- throw new Error(`Fetch failed with status ${response.status}: ${extractErrorMessage(errorBody)}`);
502
- }
503
- const responseData = (await response.json());
504
- const searchResults = responseData.map((result) => {
505
- return new place_1.MVXPlace(result);
506
- });
507
- return searchResults;
508
- }
509
- catch (error) {
510
- throw new Error("Failed to fetch and parse search results", { cause: error });
511
- }
512
- }
513
- async fetchAndParseSearchPlacesByTags(institutionId, tags, parentPlaces, sort, origin, lat, lng, floor) {
514
- try {
515
- const response = await this.requester.fetchSearchPlacesByTags(institutionId, tags, this.token, parentPlaces, sort, origin, lat, lng, floor);
516
- if (!response.ok) {
517
- const errorBody = await response.json();
518
- throw new Error(`Fetch failed with status ${response.status}: ${extractErrorMessage(errorBody)}`);
519
- }
520
- const responseData = (await response.json());
521
- const places = responseData.map((place) => new place_1.MVXPlace(place));
522
- this.logEvent("fetchAndParseSearchPlacesByTags");
523
- places.forEach((place) => {
524
- if (!this.cache.hasPlace(place.mapvxId, this.currentLang)) {
525
- this.cache.setPlace(place.mapvxId, place, this.currentLang);
526
- }
527
- if (place.clientId != null && !this.cache.hasPlace(place.clientId, this.currentLang)) {
528
- this.cache.setPlace(place.clientId, place, this.currentLang);
529
- }
530
- });
531
- return places;
532
- }
533
- catch (error) {
534
- throw new Error("Failed to fetch and parse search places by tags", { cause: error });
535
- }
536
- }
537
- async fetchAndParseRoutesFromOrigin(parentPlaceId, fromPlaceId, announceFormat, unitSystem, mode) {
538
- try {
539
- const response = await this.requester.fetchRoutesForOrigin(this.token, parentPlaceId, fromPlaceId, announceFormat, unitSystem, mode);
540
- if (!response.ok) {
541
- const errorBody = await response.json();
542
- throw new Error(`Fetch failed with status ${response.status}: ${extractErrorMessage(errorBody)}`);
543
- }
544
- const { routes, accessibleRoutes } = (await response.json());
545
- Object.entries(routes).forEach(([destinationId, routeResponse]) => {
546
- const route = new route_1.MVXRoute(routeResponse[0]);
547
- this.cache.setRoute(destinationId, {
548
- timestamp: Date.now(),
549
- data: route,
550
- });
551
- });
552
- Object.entries(accessibleRoutes).forEach(([destinationId, routeResponse]) => {
553
- const route = new route_1.MVXRoute(routeResponse[0]);
554
- this.cache.setAccessibleRoute(destinationId, {
555
- timestamp: Date.now(),
556
- data: route,
557
- });
558
- });
559
- this.debugLog("Route cache testing. Cache populated!");
560
- }
561
- catch (error) {
562
- throw new Error("Failed to fetch and parse routes from origin results", { cause: error });
563
- }
564
- }
565
- async fetchAndParseCacheTimestamp(parentPlaceId) {
566
- try {
567
- const response = await this.requester.fetchCacheTimestamp(this.token, parentPlaceId);
568
- if (!response.ok) {
569
- const errorBody = await response.json();
570
- throw new Error(`Fetch failed with status ${response.status}: ${extractErrorMessage(errorBody)}`);
571
- }
572
- const { lastUpdate } = (await response.json());
573
- return lastUpdate;
574
- }
575
- catch (error) {
576
- throw new Error("Failed to fetch and parse cache timestamp", { cause: error });
577
- }
578
- }
579
- cleanRoutesCache() {
580
- this.cache.cleanRoutesCache();
581
- this.cache.cleanAccessibleRoutesCache();
582
- }
583
- async fetchAndParseConfiguration(placeId, product) {
584
- try {
585
- // Check cache first
586
- const cachedConfig = this.cache.getConfiguration(placeId || "default", product || "default", this.currentLang);
587
- if (cachedConfig != null) {
588
- this.logEvent("fetchAndParseConfiguration", { cached: "true" });
589
- return cachedConfig.data;
590
- }
591
- const response = await this.requester.fetchConfiguration(this.token, placeId, product);
592
- if (!response.ok) {
593
- const errorBody = await response.json();
594
- throw new Error(`Fetch failed with status ${response.status}: ${extractErrorMessage(errorBody)}`);
595
- }
596
- const config = (await response.json());
597
- // Cache the result
598
- this.cache.setConfiguration(placeId || "default", product || "default", this.currentLang, {
599
- timestamp: Date.now(),
600
- data: config,
601
- });
602
- this.logEvent("fetchAndParseConfiguration", { cached: "false" });
603
- return config;
604
- }
605
- catch (error) {
606
- this.logError(error, { functionName: "fetchAndParseConfiguration" });
607
- throw new Error("Failed to fetch and parse configuration", { cause: error });
608
- }
609
- }
610
- /**
611
- * Fetches the campaigns for a maps-group (totem screensaver playlist). Returns them
612
- * verbatim — no status/date/schedule filtering, that is the consumer's decision.
613
- * `placeId` is the maps-group firebase id; `kioskId` optionally narrows to a totem.
614
- * Not cached (campaigns change; the totem keeps its own short-lived cache).
615
- */
616
- async fetchAndParseCampaigns(placeId, kioskId) {
617
- try {
618
- const response = await this.requester.fetchCampaigns(this.token, placeId, kioskId);
619
- if (!response.ok) {
620
- const errorBody = await response.json();
621
- throw new Error(`Fetch failed with status ${response.status}: ${extractErrorMessage(errorBody)}`);
622
- }
623
- const raw = (await response.json());
624
- // A non-array body is a contract break (a `{ campaigns: [...] }` wrapper, an HTML
625
- // error page served with a 200). Degrading to an empty playlist keeps the totem
626
- // running, but it must not look like a successful empty fetch — without this
627
- // warning the screensaver just goes blank with nothing to diagnose.
628
- if (!Array.isArray(raw)) {
629
- this.logWarning(new Error("Campaigns response body was not an array"), {
630
- functionName: "fetchAndParseCampaigns",
631
- receivedType: raw === null ? "null" : typeof raw,
632
- });
633
- }
634
- const campaigns = (Array.isArray(raw) ? raw : []).map((item) => new campaign_1.Campaign(item));
635
- this.logEvent("fetchAndParseCampaigns", { count: String(campaigns.length) });
636
- return campaigns;
637
- }
638
- catch (error) {
639
- this.logError(error, { functionName: "fetchAndParseCampaigns" });
640
- throw new Error("Failed to fetch and parse campaigns", { cause: error });
641
- }
642
- }
643
- async fetchAndParseCategories(placeId) {
644
- try {
645
- // Check cache first
646
- const cachedCategories = this.cache.getCategories(placeId || "default", this.currentLang);
647
- if (cachedCategories != null) {
648
- this.logEvent("fetchAndParseCategories", { cached: "true" });
649
- return cachedCategories.data;
650
- }
651
- const response = await this.requester.fetchCategories(this.token, placeId);
652
- if (!response.ok) {
653
- const errorBody = await response.json();
654
- throw new Error(`Fetch failed with status ${response.status}: ${extractErrorMessage(errorBody)}`);
655
- }
656
- const categories = (await response.json());
657
- // Cache the result
658
- this.cache.setCategories(placeId || "default", this.currentLang, {
659
- timestamp: Date.now(),
660
- data: categories,
661
- });
662
- this.logEvent("fetchAndParseCategories", { cached: "false" });
663
- return categories;
664
- }
665
- catch (error) {
666
- throw new Error("Failed to fetch and parse categories", { cause: error });
667
- }
668
- }
669
- async fetchAndParseCssCustomization(type) {
670
- try {
671
- const response = await this.requester.fetchCssCustomization(this.token, type);
672
- if (!response.ok) {
673
- const errorBody = await response.json();
674
- throw new Error(`Fetch failed with status ${response.status}: ${extractErrorMessage(errorBody)}`);
675
- }
676
- const cssCustomization = (await response.json());
677
- return cssCustomization;
678
- }
679
- catch (error) {
680
- throw new Error("Failed to fetch and parse css customization", { cause: error });
681
- }
682
- }
683
- async postAndParseHealthPing(healthPingId, placeId, totemId, status) {
684
- const response = await this.requester.postHealth(this.token, healthPingId, placeId, totemId, status);
685
- if (!response.ok) {
686
- const errorBody = await response.json();
687
- throw new Error(`Post failed with status ${response.status}: ${extractErrorMessage(errorBody)}`);
688
- }
689
- const data = (await response.json());
690
- return data;
691
- }
692
- }
693
- exports.Repository = Repository;
694
- //# sourceMappingURL=repository.js.map