@kosdev-code/kos-dispense-sdk 2.1.38 → 2.1.40

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 (38) hide show
  1. package/dispense-registration-manager-C6k10ipu.cjs +2698 -0
  2. package/dispense-registration-manager-C6k10ipu.cjs.map +1 -0
  3. package/dispense-registration-manager-lJlcyq5G.js +2700 -0
  4. package/dispense-registration-manager-lJlcyq5G.js.map +1 -0
  5. package/{extension-utils-DrsPfQWC.js → extension-utils-AS0Z5eod.js} +194 -157
  6. package/{extension-utils-DrsPfQWC.js.map → extension-utils-AS0Z5eod.js.map} +1 -1
  7. package/extension-utils-DNbm2KRk.cjs +500 -0
  8. package/{extension-utils-BDyaRwRN.cjs.map → extension-utils-DNbm2KRk.cjs.map} +1 -1
  9. package/index.cjs +142 -1
  10. package/index.cjs.map +1 -1
  11. package/index.js +124 -121
  12. package/index.js.map +1 -1
  13. package/kos-models.json +1 -1
  14. package/models/models/assembly/holder-utils.d.ts.map +1 -1
  15. package/models/models/holder/holder-model.d.ts.map +1 -1
  16. package/models/models/holder/types/index.d.ts +2 -0
  17. package/models/models/nozzle/nozzle-model.d.ts +1 -0
  18. package/models/models/nozzle/nozzle-model.d.ts.map +1 -1
  19. package/models/models/types/assembly.d.ts +1 -0
  20. package/models/models/types/assembly.d.ts.map +1 -1
  21. package/models.cjs +47 -1
  22. package/models.cjs.map +1 -1
  23. package/models.js +40 -40
  24. package/package.json +14 -2
  25. package/pump-provider-BSEusYig.js +1825 -0
  26. package/{pump-provider-Bytd6qXc.js.map → pump-provider-BSEusYig.js.map} +1 -1
  27. package/pump-provider-D4Ed_gH6.cjs +1824 -0
  28. package/{pump-provider-CTELJBW5.cjs.map → pump-provider-D4Ed_gH6.cjs.map} +1 -1
  29. package/ui.cjs +73 -1
  30. package/ui.cjs.map +1 -1
  31. package/ui.js +67 -67
  32. package/dispense-registration-manager-Cj0565Ze.cjs +0 -2
  33. package/dispense-registration-manager-Cj0565Ze.cjs.map +0 -1
  34. package/dispense-registration-manager-CzAqcL8D.js +0 -2044
  35. package/dispense-registration-manager-CzAqcL8D.js.map +0 -1
  36. package/extension-utils-BDyaRwRN.cjs +0 -2
  37. package/pump-provider-Bytd6qXc.js +0 -1308
  38. package/pump-provider-CTELJBW5.cjs +0 -2
@@ -0,0 +1,2698 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
+ var __publicField = (obj, key, value) => {
5
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
6
+ return value;
7
+ };
8
+ const kosUiSdk = require("@kosdev-code/kos-ui-sdk");
9
+ require("react");
10
+ var ExtensionType = /* @__PURE__ */ ((ExtensionType2) => {
11
+ ExtensionType2["IngredientLoader"] = "kos.ingredient.loader";
12
+ ExtensionType2["IngredientMapper"] = "kos.ingredient.mapper";
13
+ ExtensionType2["IngredientIndex"] = "kos.ingredient.index";
14
+ ExtensionType2["IngredientTypeMapper"] = "kos.ingredient.type.mapper";
15
+ ExtensionType2["HolderTypeMapper"] = "kos.holder.type.mapper";
16
+ ExtensionType2["HolderMapper"] = "kos.holder.mapper";
17
+ ExtensionType2["HolderIndex"] = "kos.holder.index";
18
+ ExtensionType2["HolderIngredientMapper"] = "kos.holder.ingredient.mapper";
19
+ ExtensionType2["AvailabilityMapper"] = "kos.availability.mapper";
20
+ ExtensionType2["AvailabilityLoader"] = "kos.availability.loader";
21
+ ExtensionType2["SelectedPourableMapper"] = "kos.selected.pourable.mapper";
22
+ ExtensionType2["AssemblyMapper"] = "kos.assembly.mapper";
23
+ ExtensionType2["BoardMapper"] = "kos.board.mapper";
24
+ ExtensionType2["BoardIndex"] = "kos.board.index";
25
+ ExtensionType2["PumpIndex"] = "kos.pump.index";
26
+ ExtensionType2["AssemblyFeatureFlags"] = "kos.assembly.feature.flags";
27
+ return ExtensionType2;
28
+ })(ExtensionType || {});
29
+ var DispenseModelType = /* @__PURE__ */ ((DispenseModelType2) => {
30
+ DispenseModelType2["Nozzle"] = "nozzle-model";
31
+ DispenseModelType2["Availability"] = "availability-model";
32
+ DispenseModelType2["Holder"] = "holder-model";
33
+ DispenseModelType2["HolderContainer"] = "holder-container-model";
34
+ DispenseModelType2["IngredientContainer"] = "ingredient-container-model";
35
+ DispenseModelType2["Ingredient"] = "ingredient-model";
36
+ DispenseModelType2["Pump"] = "pump-model";
37
+ DispenseModelType2["PumpContainer"] = "pump-container-model";
38
+ return DispenseModelType2;
39
+ })(DispenseModelType || {});
40
+ var __getOwnPropDesc$c = Object.getOwnPropertyDescriptor;
41
+ var __decorateClass$c = (decorators, target, key, kind) => {
42
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$c(target, key) : target;
43
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
44
+ if (decorator = decorators[i])
45
+ result = decorator(result) || result;
46
+ return result;
47
+ };
48
+ const MODEL_TYPE$c = "ingredient-model";
49
+ let IngredientModelImpl = class {
50
+ constructor(modelId, {
51
+ name,
52
+ type,
53
+ data,
54
+ ingredientId,
55
+ ...rest
56
+ }) {
57
+ __publicField(this, "id");
58
+ __publicField(this, "ingredientId");
59
+ __publicField(this, "name");
60
+ __publicField(this, "type");
61
+ __publicField(this, "data");
62
+ this.id = modelId;
63
+ this.ingredientId = ingredientId;
64
+ this.name = name;
65
+ this.type = type;
66
+ this.data = data;
67
+ Object.assign(this, rest);
68
+ }
69
+ updateModel({
70
+ name,
71
+ type,
72
+ data,
73
+ ingredientId,
74
+ ...rest
75
+ }) {
76
+ this.name = name;
77
+ this.type = type;
78
+ this.ingredientId = ingredientId;
79
+ this.data = data;
80
+ Object.assign(this, rest);
81
+ }
82
+ // -------------------LIFECYCLE----------------------------
83
+ // -------------------ENTITY----------------------------
84
+ };
85
+ IngredientModelImpl = __decorateClass$c([
86
+ kosUiSdk.kosModel(MODEL_TYPE$c)
87
+ ], IngredientModelImpl);
88
+ const Ingredient = {
89
+ registration: {
90
+ [MODEL_TYPE$c]: {
91
+ class: IngredientModelImpl,
92
+ singleton: false
93
+ }
94
+ },
95
+ type: MODEL_TYPE$c,
96
+ predicate: kosUiSdk.isKosModel(MODEL_TYPE$c),
97
+ factory: kosUiSdk.Kos.Factory.create(MODEL_TYPE$c)
98
+ };
99
+ const { URL: URL$6 } = kosUiSdk.resolveServiceUrl("INGREDIENT_SERVICE");
100
+ const { getOne: getOne$3 } = kosUiSdk.ServiceFactory.build({
101
+ basePath: `${URL$6}/api/ext/dispense/ingredients`
102
+ });
103
+ const getIngredients = async () => {
104
+ const response = await getOne$3({
105
+ urlOverride: `${URL$6}/api/ext/dispense/ingredients`
106
+ });
107
+ return response;
108
+ };
109
+ var __defProp$9 = Object.defineProperty;
110
+ var __getOwnPropDesc$b = Object.getOwnPropertyDescriptor;
111
+ var __decorateClass$b = (decorators, target, key, kind) => {
112
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$b(target, key) : target;
113
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
114
+ if (decorator = decorators[i])
115
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
116
+ if (kind && result)
117
+ __defProp$9(target, key, result);
118
+ return result;
119
+ };
120
+ const MODEL_TYPE$b = "ingredient-container-model";
121
+ const log$3 = kosUiSdk.KosLog.createLogger({ name: "ingredient-container-model" });
122
+ let IngredientContainerModelImpl = class {
123
+ constructor(modelId, options) {
124
+ __publicField(this, "id");
125
+ __publicField(this, "ingredients");
126
+ this.id = modelId;
127
+ this.ingredients = new kosUiSdk.KosModelContainer({
128
+ indexMap: {
129
+ ingredientType: "type"
130
+ },
131
+ extensionId: ExtensionType.IngredientIndex,
132
+ parentId: modelId
133
+ });
134
+ }
135
+ updateModel() {
136
+ }
137
+ // -------------------LIFECYCLE----------------------------
138
+ getIngredientsByType(type) {
139
+ return this.ingredients.getIndexByKey("ingredientType", type);
140
+ }
141
+ async load(context) {
142
+ var _a;
143
+ log$3.debug(`loading ingredient container ${this.id}`);
144
+ const allIngredients = await getIngredients();
145
+ if ((allIngredients == null ? void 0 : allIngredients.status) !== 200) {
146
+ throw new Error("Failed to load ingredients");
147
+ }
148
+ const ingredientContext = await kosUiSdk.KosExtensionUtils.executeLoaderExtension({
149
+ context,
150
+ extension: ExtensionType.IngredientLoader
151
+ });
152
+ const ingredientData = (allIngredients == null ? void 0 : allIngredients.data) ?? {};
153
+ for (const key of Object.keys(ingredientData)) {
154
+ for (const ingredientData2 of ((_a = allIngredients == null ? void 0 : allIngredients.data) == null ? void 0 : _a[key]) || []) {
155
+ const data = await kosUiSdk.KosExtensionUtils.executeDataMapperExtension({
156
+ extension: ExtensionType.IngredientMapper,
157
+ data: ingredientData2,
158
+ contextData: ingredientContext
159
+ });
160
+ const type = await kosUiSdk.KosExtensionUtils.executePropertyMapperExtension({
161
+ extension: ExtensionType.IngredientTypeMapper,
162
+ data: ingredientData2,
163
+ contextData: ingredientContext
164
+ });
165
+ const ingredientOptions = {
166
+ ...ingredientData2,
167
+ type: type || ingredientData2.type,
168
+ ...data,
169
+ data
170
+ };
171
+ const ingredient = Ingredient.factory(ingredientData2.id)(
172
+ ingredientOptions
173
+ );
174
+ this.ingredients.addModel(ingredient);
175
+ }
176
+ }
177
+ }
178
+ // -------------------ENTITY----------------------------
179
+ };
180
+ __decorateClass$b([
181
+ kosUiSdk.kosChild
182
+ ], IngredientContainerModelImpl.prototype, "ingredients", 2);
183
+ IngredientContainerModelImpl = __decorateClass$b([
184
+ kosUiSdk.kosModel(MODEL_TYPE$b)
185
+ ], IngredientContainerModelImpl);
186
+ const IngredientContainer = {
187
+ registration: {
188
+ [MODEL_TYPE$b]: {
189
+ class: IngredientContainerModelImpl,
190
+ singleton: true
191
+ }
192
+ },
193
+ type: MODEL_TYPE$b,
194
+ predicate: kosUiSdk.isKosModel(MODEL_TYPE$b),
195
+ factory: kosUiSdk.Kos.Singleton.create(MODEL_TYPE$b)
196
+ };
197
+ const { URL: URL$5 } = kosUiSdk.resolveServiceUrl("HOLDER_SERVICE");
198
+ const { getAll: getAll$1, postModel: postModel$4, deleteModel: deleteModel$2 } = kosUiSdk.ServiceFactory.build({
199
+ basePath: `${URL$5}/api/kos/holders`
200
+ });
201
+ const log$2 = kosUiSdk.KosLog.createLogger({
202
+ name: "holder-service",
203
+ group: "Services"
204
+ });
205
+ const getHolders = async () => {
206
+ const response = await getAll$1({});
207
+ return response;
208
+ };
209
+ const assignHolderIngredient = async (holderPath, ingredientId) => {
210
+ if (!holderPath || !ingredientId) {
211
+ throw new Error("Missing holderPath or ingredientId");
212
+ }
213
+ const response = await postModel$4({
214
+ model: { holderPath, ingredientId },
215
+ urlOverride: `${URL$5}/api/ext/dispense/assignments`
216
+ });
217
+ return response;
218
+ };
219
+ const unassignHolderIngredient = async (holderPath) => {
220
+ if (!holderPath) {
221
+ throw new Error("Missing holderPath");
222
+ }
223
+ const response = await deleteModel$2({
224
+ id: holderPath,
225
+ urlOverride: `${URL$5}/api/ext/dispense/assignments/${holderPath}`
226
+ });
227
+ return response;
228
+ };
229
+ const replaceLine = async (holderPath) => {
230
+ if (!holderPath)
231
+ throw new Error("Missing holderPath");
232
+ log$2.debug(
233
+ `sending POST request to /api/ext/dispense/pumpEvents/replaceLine/${holderPath}`
234
+ );
235
+ const response = await postModel$4({
236
+ model: {},
237
+ urlOverride: `${URL$5}/api/ext/dispense/pumpEvents/replaceLine/${holderPath}`
238
+ });
239
+ return response;
240
+ };
241
+ const { URL: URL$4 } = kosUiSdk.resolveServiceUrl("ASSIGNMENT_SERVICE");
242
+ const { getAll, postModel: postModel$3, deleteModel: deleteModel$1 } = kosUiSdk.ServiceFactory.build({
243
+ destinationAddress: "",
244
+ basePath: `${URL$4}/api/ext/dispense/assignments`
245
+ });
246
+ const useFos = window.kosUseFos;
247
+ const getAssignments = async () => {
248
+ const response = await getAll({ fos: useFos });
249
+ return response;
250
+ };
251
+ const sendRfidOverride = async (holderPath, overrides) => {
252
+ var _a, _b, _c, _d;
253
+ const factoryJson = JSON.stringify(overrides);
254
+ const url = `${URL$4}/api/ext/dispense/assignments`;
255
+ try {
256
+ const response = await postModel$3({
257
+ model: { holderPath, factoryJson },
258
+ urlOverride: url
259
+ });
260
+ if ((response == null ? void 0 : response.status) === 200 && ((_a = response == null ? void 0 : response.data) == null ? void 0 : _a.error)) {
261
+ return [response.data.error || "unknownError", response.data];
262
+ }
263
+ return [void 0, response == null ? void 0 : response.data];
264
+ } catch (error) {
265
+ if (error instanceof kosUiSdk.FetchError) {
266
+ return [
267
+ ((_c = (_b = error.payload) == null ? void 0 : _b.data) == null ? void 0 : _c.error) || "unknownError",
268
+ (_d = error.payload) == null ? void 0 : _d.data
269
+ ];
270
+ }
271
+ }
272
+ return ["unknownError", void 0];
273
+ };
274
+ const addAssignment = async (assignment) => {
275
+ const url = useFos ? `${URL$4}/api/ingredients/assignments/${assignment.holderPath}` : `${URL$4}/api/ext/dispense/assignments`;
276
+ const response = await postModel$3({
277
+ model: { ...assignment, fuelGauge: 680 },
278
+ fos: useFos,
279
+ urlOverride: url
280
+ });
281
+ return response;
282
+ };
283
+ const deleteAssignment = async (id) => {
284
+ const response = await deleteModel$1({ id, fos: useFos });
285
+ return response;
286
+ };
287
+ var __defProp$8 = Object.defineProperty;
288
+ var __getOwnPropDesc$a = Object.getOwnPropertyDescriptor;
289
+ var __decorateClass$a = (decorators, target, key, kind) => {
290
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$a(target, key) : target;
291
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
292
+ if (decorator = decorators[i])
293
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
294
+ if (kind && result)
295
+ __defProp$8(target, key, result);
296
+ return result;
297
+ };
298
+ const MODEL_TYPE$a = DispenseModelType.Holder;
299
+ const log$1 = kosUiSdk.KosLog.createLogger({ name: "holder-model" });
300
+ kosUiSdk.ExtensionManager[kosUiSdk.EXTENSION_TROUBLE_MAPPER].register(
301
+ "holder",
302
+ async (trouble) => {
303
+ const result = [];
304
+ result.push(...trouble.data.holderPaths);
305
+ return result;
306
+ }
307
+ );
308
+ kosUiSdk.ExtensionManager[kosUiSdk.EXTENSION_TROUBLE_DATA_MAPPER].register(
309
+ "pump",
310
+ async (trouble) => {
311
+ if (trouble.data.pumpPath) {
312
+ const { model: pumpModel } = kosUiSdk.getKosModelSync(
313
+ trouble.data.pumpPath
314
+ );
315
+ if (pumpModel) {
316
+ const ingredientModel = pumpModel.ingredientId ? kosUiSdk.getKosModelSync(pumpModel.ingredientId).model : void 0;
317
+ return {
318
+ ingredientId: pumpModel.ingredientId,
319
+ ingredientName: (ingredientModel == null ? void 0 : ingredientModel.displayName) ?? ((ingredientModel == null ? void 0 : ingredientModel.name) || ""),
320
+ childPumpName: pumpModel.name
321
+ };
322
+ }
323
+ }
324
+ return {};
325
+ }
326
+ );
327
+ kosUiSdk.ExtensionManager[kosUiSdk.EXTENSION_TROUBLE_DATA_MAPPER].register(
328
+ "holder",
329
+ async (trouble) => {
330
+ if (trouble.data.holderNames.length > 0) {
331
+ const holderName = trouble.data.holderNames[0];
332
+ return {
333
+ holderName: holderName || ""
334
+ };
335
+ }
336
+ return {};
337
+ }
338
+ );
339
+ kosUiSdk.ExtensionManager[kosUiSdk.EXTENSION_TROUBLE_DATA_MAPPER].register(
340
+ "container",
341
+ async (trouble) => {
342
+ if (trouble.data.ingredients.length > 0) {
343
+ const ingredientId = trouble.data.ingredients[0];
344
+ const { model } = kosUiSdk.getKosModelSync(ingredientId);
345
+ return {
346
+ ingredientName: (model == null ? void 0 : model.displayName) ?? ((model == null ? void 0 : model.name) || ""),
347
+ ingredients: trouble.data.ingredients ? trouble.data.ingredients : [],
348
+ unknonwnIngredientId: trouble.data.unknonwnIngredientId ?? ""
349
+ };
350
+ }
351
+ return {};
352
+ }
353
+ );
354
+ class AssignmentError extends Error {
355
+ constructor(type, message) {
356
+ super(message);
357
+ __publicField(this, "type");
358
+ this.name = "AssignmentError";
359
+ this.type = type;
360
+ }
361
+ }
362
+ let HolderModelImpl = class {
363
+ constructor(modelId, {
364
+ path,
365
+ name,
366
+ ingredientSource,
367
+ ingredientId,
368
+ ingredientType,
369
+ slice,
370
+ group,
371
+ data,
372
+ enjoyByDate,
373
+ attributes
374
+ }, context) {
375
+ __publicField(this, "id");
376
+ __publicField(this, "path");
377
+ __publicField(this, "name");
378
+ __publicField(this, "ingredientId");
379
+ __publicField(this, "ingredientType");
380
+ __publicField(this, "ingredientSource");
381
+ __publicField(this, "group");
382
+ __publicField(this, "slice");
383
+ __publicField(this, "logger");
384
+ __publicField(this, "data");
385
+ __publicField(this, "enjoyByDate");
386
+ __publicField(this, "attributes");
387
+ __publicField(this, "pumps");
388
+ __publicField(this, "ingredientContainer");
389
+ this.id = modelId;
390
+ this.path = path;
391
+ this.name = name;
392
+ this.ingredientType = ingredientType;
393
+ this.ingredientSource = ingredientSource;
394
+ this.ingredientId = ingredientId;
395
+ this.group = group;
396
+ this.slice = slice;
397
+ this.enjoyByDate = enjoyByDate;
398
+ this.data = data;
399
+ this.pumps = new kosUiSdk.KosModelContainer({
400
+ parentId: modelId,
401
+ sortKey: "path"
402
+ });
403
+ this.attributes = attributes || {};
404
+ this.logger = context.logger;
405
+ }
406
+ updateModel({
407
+ path,
408
+ name,
409
+ ingredientSource,
410
+ ingredientId,
411
+ ingredientType,
412
+ group,
413
+ slice,
414
+ enjoyByDate,
415
+ data
416
+ }) {
417
+ this.path = path;
418
+ this.name = name;
419
+ this.ingredientId = ingredientId;
420
+ this.ingredientType = ingredientType;
421
+ this.ingredientSource = ingredientSource;
422
+ this.enjoyByDate = enjoyByDate;
423
+ this.slice = slice;
424
+ this.group = group;
425
+ this.data = data;
426
+ }
427
+ get hasEnjoyByDate() {
428
+ return !!this.enjoyByDate && !this.unassigned;
429
+ }
430
+ get hasEnjoyByWarning() {
431
+ var _a;
432
+ return ((_a = this.troublesByType["EnjoyByTrouble"]) == null ? void 0 : _a.length) > 0;
433
+ }
434
+ get nozzlePaths() {
435
+ return this.pumps.data.map((pump) => pump.nozzlePath);
436
+ }
437
+ async cancelPour() {
438
+ await Promise.all(
439
+ this.pumps.data.filter((pump) => pump.isPouring).map((pump) => pump.cancelPour())
440
+ );
441
+ }
442
+ get canPour() {
443
+ return !this.shouldDefer && this.pumps.data.every((pump) => pump.canPour);
444
+ }
445
+ get isPouring() {
446
+ const _isPouring = this.pumps.data.some((pump) => pump.isPouring);
447
+ this.logger.debug(`isPouring: ${!!_isPouring}`);
448
+ return _isPouring;
449
+ }
450
+ async performIntent(props) {
451
+ const intent = typeof props === "string" ? props : props.intent;
452
+ const pumpPath = typeof props === "string" ? void 0 : props.pumpPath;
453
+ const pump = pumpPath ? this.pumps.getModel(pumpPath) : this.pumps.data[0];
454
+ return pump == null ? void 0 : pump.performIntent({ intent });
455
+ }
456
+ get pourState() {
457
+ const state = this.pumps.data.reduce((resolvedState, pump) => {
458
+ if (pump.pouringState) {
459
+ return pump.pouringState;
460
+ }
461
+ return resolvedState;
462
+ }, "");
463
+ return state;
464
+ }
465
+ get nozzlePath() {
466
+ var _a;
467
+ return (_a = this.pumps.data[0]) == null ? void 0 : _a.nozzlePath;
468
+ }
469
+ get pumpPaths() {
470
+ return this.pumps.data.map((pump) => pump.id);
471
+ }
472
+ get sortedPumps() {
473
+ return this.pumps.data.sort((a, b) => {
474
+ if (a.virtual && !b.virtual) {
475
+ return -1;
476
+ }
477
+ if (!a.virtual && b.virtual) {
478
+ return 1;
479
+ }
480
+ return a.name.localeCompare(b.name);
481
+ });
482
+ }
483
+ get ingredient() {
484
+ var _a;
485
+ if (!this.ingredientId) {
486
+ return void 0;
487
+ }
488
+ const ingredient = (_a = this.ingredientContainer) == null ? void 0 : _a.ingredients.getModel(
489
+ this.ingredientId
490
+ );
491
+ return ingredient;
492
+ }
493
+ get ingredientName() {
494
+ if (this.ingredient) {
495
+ return this.ingredient.displayName ?? this.ingredient.name;
496
+ } else if (this.ingredientId) {
497
+ return "unknown";
498
+ } else {
499
+ return "";
500
+ }
501
+ }
502
+ get previousIngredient() {
503
+ var _a;
504
+ if (!this.prevIngredientId) {
505
+ return void 0;
506
+ }
507
+ const ingredient = (_a = this.ingredientContainer) == null ? void 0 : _a.ingredients.getModel(
508
+ this.prevIngredientId
509
+ );
510
+ return ingredient;
511
+ }
512
+ get previousIngredientName() {
513
+ if (this.previousIngredient) {
514
+ return this.previousIngredient.displayName ?? this.previousIngredient.name;
515
+ } else if (this.prevIngredientId) {
516
+ return "unknown";
517
+ } else {
518
+ return "";
519
+ }
520
+ }
521
+ get prevIngredientId() {
522
+ var _a, _b;
523
+ return (_b = (_a = this.pumps.data) == null ? void 0 : _a[0]) == null ? void 0 : _b.prevIngredientId;
524
+ }
525
+ get unassigned() {
526
+ return (!this.ingredientId || this.ingredientId === "0") && (!this.prevIngredientId || this.prevIngredientId === "0");
527
+ }
528
+ get removed() {
529
+ return (!this.ingredientId || this.ingredientId === "0") && this.prevIngredientId !== void 0 && this.prevIngredientId !== "0";
530
+ }
531
+ get maxVolume() {
532
+ return this.slice.maxVolMl ?? 0;
533
+ }
534
+ get remainingVolume() {
535
+ return this.slice.currentVolMl ?? 0;
536
+ }
537
+ get hasMaxVolume() {
538
+ return this.slice.maxVolMl !== void 0;
539
+ }
540
+ get hasRemainingVolume() {
541
+ return this.slice.currentVolMl !== void 0;
542
+ }
543
+ get fillPercent() {
544
+ return this.remainingVolume <= 0 ? 0 : Math.floor((this.remainingVolume || 1) / (this.maxVolume || 1) * 100);
545
+ }
546
+ get hasFuelGuage() {
547
+ return this.hasMaxVolume && this.hasRemainingVolume;
548
+ }
549
+ updateIngredient(ingredientId) {
550
+ if (this.ingredientId === ingredientId) {
551
+ return;
552
+ }
553
+ kosUiSdk.kosAction(() => {
554
+ this.ingredientId = ingredientId;
555
+ });
556
+ }
557
+ async resolveIntentVolume(intent) {
558
+ const pump = this.pumps.data[0];
559
+ if (!pump) {
560
+ return { volume: -1 };
561
+ }
562
+ return pump.resolveIntentVolume(intent);
563
+ }
564
+ async overrideRfidCode(overrides) {
565
+ if (!overrides) {
566
+ throw new Error("Invalid override");
567
+ }
568
+ try {
569
+ const [error, result] = await sendRfidOverride(this.path, overrides);
570
+ if (error) {
571
+ throw new AssignmentError(
572
+ error,
573
+ `Failed to perform rfid override on holder ${this.id}`
574
+ );
575
+ }
576
+ kosUiSdk.kosAction(() => {
577
+ this.ingredientId = result == null ? void 0 : result.ingredientId;
578
+ });
579
+ return result;
580
+ } catch (e) {
581
+ log$1.error(`Failed to perform rfid override on holder ${this.id}`, e);
582
+ throw e;
583
+ }
584
+ }
585
+ async assignIngredient(ingredientId) {
586
+ try {
587
+ if (ingredientId) {
588
+ await assignHolderIngredient(this.path, ingredientId);
589
+ } else {
590
+ await unassignHolderIngredient(this.path);
591
+ }
592
+ kosUiSdk.kosAction(() => {
593
+ this.ingredientId = ingredientId;
594
+ });
595
+ } catch (e) {
596
+ log$1.error(`Failed to perform assign ingredient to holder ${this.id}`, e);
597
+ throw e;
598
+ }
599
+ }
600
+ /**
601
+ * @kosApiLevel 3
602
+ */
603
+ get shouldDefer() {
604
+ return this.troubles.some((trouble) => trouble.shouldDefer);
605
+ }
606
+ async replaceLine() {
607
+ await replaceLine(this.path);
608
+ return;
609
+ }
610
+ // -------------------LIFECYCLE----------------------------
611
+ // ----------------------------------
612
+ // UNCOMMENT FOR TESTING FUEL GAUGE
613
+ // ----------------------------------
614
+ // async load() {
615
+ // const random = Math.max(1000, Math.floor(Math.random() * 5000));
616
+ // this.slice.maxVolMl = 1000;
617
+ // setInterval(() => {
618
+ // kosAction(() => {
619
+ // if (this.remainingVolume < -100) {
620
+ // this.slice.maxVolMl = 1000;
621
+ // this.slice.currentVolMl = this.maxVolume;
622
+ // } else {
623
+ // this.slice.currentVolMl = this.remainingVolume - 50;
624
+ // }
625
+ // });
626
+ // }, random);
627
+ // }
628
+ // -------------------ENTITY----------------------------
629
+ };
630
+ __decorateClass$a([
631
+ kosUiSdk.kosChild
632
+ ], HolderModelImpl.prototype, "pumps", 2);
633
+ __decorateClass$a([
634
+ kosUiSdk.kosDependency({ modelType: IngredientContainer.type })
635
+ ], HolderModelImpl.prototype, "ingredientContainer", 2);
636
+ HolderModelImpl = __decorateClass$a([
637
+ kosUiSdk.kosModel(MODEL_TYPE$a),
638
+ kosUiSdk.kosTroubleAware()
639
+ ], HolderModelImpl);
640
+ const Holder = {
641
+ registration: {
642
+ [MODEL_TYPE$a]: {
643
+ class: HolderModelImpl,
644
+ singleton: false
645
+ }
646
+ },
647
+ type: MODEL_TYPE$a,
648
+ predicate: kosUiSdk.isKosModel(MODEL_TYPE$a),
649
+ factory: kosUiSdk.Kos.Factory.create(MODEL_TYPE$a)
650
+ };
651
+ const mapAssemblyHolderToModel = async (group, holderData) => {
652
+ var _a;
653
+ const _ingredientId = kosUiSdk.ExtensionManager.propertyMapper.executeMapper(
654
+ ExtensionType.HolderIngredientMapper,
655
+ holderData
656
+ );
657
+ const type = kosUiSdk.ExtensionManager.propertyMapper.executeMapper(
658
+ ExtensionType.HolderTypeMapper,
659
+ holderData
660
+ ) || holderData.ingType;
661
+ const holderExtData = await kosUiSdk.KosExtensionUtils.executeDataMapperExtension({
662
+ extension: ExtensionType.HolderMapper,
663
+ data: holderData,
664
+ contextData: {}
665
+ });
666
+ const {
667
+ name,
668
+ path,
669
+ ingredientId,
670
+ ingType,
671
+ ingSource,
672
+ slice,
673
+ attributes,
674
+ ...rest
675
+ } = holderData;
676
+ const extData = { ...rest, ...holderExtData };
677
+ const sliceData = slice || { pos: 0 };
678
+ const holderOptions = {
679
+ name,
680
+ path,
681
+ ingredientId: _ingredientId || ingredientId,
682
+ ingredientType: type || ingType,
683
+ ingredientSource: ingSource,
684
+ enjoyByDate: ((_a = holderData.container) == null ? void 0 : _a.enjoyByDate) ? new Date(holderData.container.enjoyByDate) : void 0,
685
+ slice: sliceData,
686
+ group,
687
+ attributes,
688
+ data: extData
689
+ };
690
+ const holder = Holder.factory(holderData.path)(holderOptions);
691
+ return holder;
692
+ };
693
+ const { URL: URL$3 } = kosUiSdk.resolveServiceUrl("ASSEMBLY_SERVICE");
694
+ const { getOne: getOne$2 } = kosUiSdk.ServiceFactory.build({
695
+ basePath: `${URL$3}/api/kos/device/assemblies`
696
+ });
697
+ const log = kosUiSdk.KosLog.createLogger({
698
+ name: "assembly-service",
699
+ group: "Services"
700
+ });
701
+ const getAssembly = async () => {
702
+ log.debug("sending GET for assembly");
703
+ const response = await getOne$2({});
704
+ return response;
705
+ };
706
+ var __defProp$7 = Object.defineProperty;
707
+ var __getOwnPropDesc$9 = Object.getOwnPropertyDescriptor;
708
+ var __decorateClass$9 = (decorators, target, key, kind) => {
709
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$9(target, key) : target;
710
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
711
+ if (decorator = decorators[i])
712
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
713
+ if (kind && result)
714
+ __defProp$7(target, key, result);
715
+ return result;
716
+ };
717
+ const MODEL_TYPE$9 = "board-container-model";
718
+ const TOPIC_BOARD_LINKED = "/kos/hardware/board/linked";
719
+ const TOPIC_BOARD_UNLINKED = "/kos/hardware/board/unlinked";
720
+ exports.BoardContainerModel = class BoardContainerModel {
721
+ constructor(modelId, options, context) {
722
+ __publicField(this, "id");
723
+ __publicField(this, "logger");
724
+ __publicField(this, "models");
725
+ this.id = modelId;
726
+ this.logger = context.logger;
727
+ this.models = new kosUiSdk.KosModelContainer({
728
+ parentId: modelId,
729
+ extensionId: ExtensionType.BoardIndex
730
+ });
731
+ }
732
+ get boardList() {
733
+ return this.models.data;
734
+ }
735
+ updateModel() {
736
+ }
737
+ addModel(model) {
738
+ this.models.addModel(model);
739
+ }
740
+ removeModel(id) {
741
+ this.models.removeModel(id);
742
+ }
743
+ updateBoard(boardLinkEvent) {
744
+ const boardId = boardLinkEvent.path;
745
+ const board = this.models.getModel(boardId);
746
+ if (!board) {
747
+ this.logger.warn(`board ${boardId} not found`);
748
+ return;
749
+ }
750
+ board.updateModel(boardLinkEvent);
751
+ }
752
+ handleBoardLinkEvent(boardLinkEvent) {
753
+ this.logger.debug(`handling ${TOPIC_BOARD_LINKED} event ${boardLinkEvent}`);
754
+ if (boardLinkEvent) {
755
+ this.updateBoard(boardLinkEvent);
756
+ } else {
757
+ this.logger.debug(`- boardLinkEvent is undefined`);
758
+ }
759
+ }
760
+ handleBoardUnlinkEvent(boardLinkEvent) {
761
+ this.logger.debug(
762
+ `handling ${TOPIC_BOARD_UNLINKED} event ${boardLinkEvent}`
763
+ );
764
+ if (boardLinkEvent) {
765
+ this.updateBoard(boardLinkEvent);
766
+ } else {
767
+ this.logger.debug(`- boardLinkEvent is undefined`);
768
+ }
769
+ }
770
+ };
771
+ __decorateClass$9([
772
+ kosUiSdk.kosChild
773
+ ], exports.BoardContainerModel.prototype, "models", 2);
774
+ __decorateClass$9([
775
+ kosUiSdk.kosTopicHandler({
776
+ lifecycle: kosUiSdk.DependencyLifecycle.INIT,
777
+ topic: TOPIC_BOARD_LINKED,
778
+ websocket: true
779
+ })
780
+ ], exports.BoardContainerModel.prototype, "handleBoardLinkEvent", 1);
781
+ __decorateClass$9([
782
+ kosUiSdk.kosTopicHandler({
783
+ lifecycle: kosUiSdk.DependencyLifecycle.INIT,
784
+ topic: TOPIC_BOARD_UNLINKED,
785
+ websocket: true
786
+ })
787
+ ], exports.BoardContainerModel.prototype, "handleBoardUnlinkEvent", 1);
788
+ exports.BoardContainerModel = __decorateClass$9([
789
+ kosUiSdk.kosModel(MODEL_TYPE$9)
790
+ ], exports.BoardContainerModel);
791
+ const boardTroubleDataMapper = async (trouble) => {
792
+ const boardPath = trouble.data.boardPath;
793
+ const { model } = kosUiSdk.getKosModelSync(boardPath);
794
+ return {
795
+ boardName: (model == null ? void 0 : model.name) || ""
796
+ };
797
+ };
798
+ var __defProp$6 = Object.defineProperty;
799
+ var __getOwnPropDesc$8 = Object.getOwnPropertyDescriptor;
800
+ var __decorateClass$8 = (decorators, target, key, kind) => {
801
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$8(target, key) : target;
802
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
803
+ if (decorator = decorators[i])
804
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
805
+ if (kind && result)
806
+ __defProp$6(target, key, result);
807
+ return result;
808
+ };
809
+ const MODEL_TYPE$8 = DispenseModelType.PumpContainer;
810
+ var PumpIndex = /* @__PURE__ */ ((PumpIndex2) => {
811
+ PumpIndex2["byBoard"] = "byBoard";
812
+ PumpIndex2["byType"] = "byType";
813
+ PumpIndex2["byNozzle"] = "byNozzle";
814
+ return PumpIndex2;
815
+ })(PumpIndex || {});
816
+ let PumpContainerModelImpl = class {
817
+ constructor(modelId, options) {
818
+ __publicField(this, "id");
819
+ __publicField(this, "pumps");
820
+ this.id = modelId;
821
+ this.pumps = new kosUiSdk.KosModelContainer({
822
+ indexMap: {
823
+ byNozzle: (pump) => pump.nozzlePaths,
824
+ byBoard: (pump) => pump.boardPath,
825
+ byType: "type"
826
+ },
827
+ parentId: modelId,
828
+ extensionId: ExtensionType.PumpIndex
829
+ });
830
+ }
831
+ /**
832
+ * The collection of pump models.
833
+ */
834
+ get pumpModels() {
835
+ return this.pumps.data;
836
+ }
837
+ /**
838
+ * The collection of pump paths.
839
+ */
840
+ get pumpPaths() {
841
+ return this.pumpModels.map((pump) => pump.path);
842
+ }
843
+ addModel(model) {
844
+ this.pumps.addModel(model);
845
+ }
846
+ removeModel(id) {
847
+ this.pumps.removeModel(id);
848
+ }
849
+ getModel(id) {
850
+ return this.pumps.getModel(id);
851
+ }
852
+ get models() {
853
+ return this.pumps;
854
+ }
855
+ get data() {
856
+ return this.pumps.data;
857
+ }
858
+ updateModel() {
859
+ }
860
+ // -------------------LIFECYCLE----------------------------
861
+ async load() {
862
+ }
863
+ // -------------------ENTITY----------------------------
864
+ };
865
+ __decorateClass$8([
866
+ kosUiSdk.kosChild
867
+ ], PumpContainerModelImpl.prototype, "pumps", 2);
868
+ PumpContainerModelImpl = __decorateClass$8([
869
+ kosUiSdk.kosModel(MODEL_TYPE$8)
870
+ ], PumpContainerModelImpl);
871
+ const PumpContainer = {
872
+ registration: {
873
+ [MODEL_TYPE$8]: {
874
+ class: PumpContainerModelImpl,
875
+ singleton: true
876
+ }
877
+ },
878
+ type: MODEL_TYPE$8,
879
+ predicate: kosUiSdk.isKosModel(MODEL_TYPE$8),
880
+ factory: kosUiSdk.Kos.Singleton.create(
881
+ MODEL_TYPE$8
882
+ )
883
+ };
884
+ const getPumpRelatedPaths = async (pumpPath) => {
885
+ const result = [];
886
+ const { model } = await kosUiSdk.getKosModel(pumpPath);
887
+ if (model) {
888
+ result.push(model.boardPath);
889
+ result.push(model.nozzlePath);
890
+ result.push(model.holderPath);
891
+ }
892
+ return result;
893
+ };
894
+ const pumpTroubleResolver = async (trouble) => {
895
+ const result = [];
896
+ const pumpPath = trouble.data.pumpPath;
897
+ result.push(pumpPath);
898
+ const relatedPaths = await getPumpRelatedPaths(pumpPath);
899
+ return [...result, ...relatedPaths];
900
+ };
901
+ const boardTroubleResolver = async (trouble) => {
902
+ const result = [];
903
+ const boardPath = trouble.data.boardPath;
904
+ result.push(trouble.data.boardPath);
905
+ const pumpContainer = await kosUiSdk.getKosModel(
906
+ PumpContainer.type
907
+ );
908
+ if (pumpContainer == null ? void 0 : pumpContainer.model) {
909
+ const boardPumps = pumpContainer.model.models.getIndexByKey(
910
+ PumpIndex.byBoard,
911
+ boardPath
912
+ );
913
+ const pumpPromises = boardPumps.map(
914
+ (pump) => getPumpRelatedPaths(pump.path)
915
+ );
916
+ const pumpResults = await Promise.allSettled(pumpPromises);
917
+ pumpResults.forEach((r) => {
918
+ if (r.status === "fulfilled") {
919
+ r.value.forEach((path) => result.push(path));
920
+ }
921
+ });
922
+ }
923
+ return Array.from(new Set(result));
924
+ };
925
+ var __getOwnPropDesc$7 = Object.getOwnPropertyDescriptor;
926
+ var __decorateClass$7 = (decorators, target, key, kind) => {
927
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$7(target, key) : target;
928
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
929
+ if (decorator = decorators[i])
930
+ result = decorator(result) || result;
931
+ return result;
932
+ };
933
+ const MODEL_TYPE$7 = "board-model";
934
+ const mapOptionsToModel = (options, model) => {
935
+ const { type, name, path, linked, instanceId, link, ...rest } = options;
936
+ model.type = type;
937
+ model.name = name;
938
+ model.path = path;
939
+ model.linked = linked;
940
+ model.link = Object.freeze(link);
941
+ model.instanceId = instanceId;
942
+ Object.assign(model, rest);
943
+ };
944
+ kosUiSdk.ExtensionManager[kosUiSdk.EXTENSION_TROUBLE_MAPPER].register(
945
+ "board",
946
+ boardTroubleResolver
947
+ );
948
+ kosUiSdk.ExtensionManager[kosUiSdk.EXTENSION_TROUBLE_DATA_MAPPER].register(
949
+ "board",
950
+ boardTroubleDataMapper
951
+ );
952
+ let BoardModelImpl = class {
953
+ constructor(modelId, options, context) {
954
+ __publicField(this, "id");
955
+ __publicField(this, "type");
956
+ __publicField(this, "name");
957
+ __publicField(this, "path");
958
+ __publicField(this, "linked");
959
+ __publicField(this, "instanceId");
960
+ __publicField(this, "logger");
961
+ this.id = modelId;
962
+ this.logger = context.logger;
963
+ mapOptionsToModel(options, this);
964
+ }
965
+ updateModel(options) {
966
+ mapOptionsToModel(options, this);
967
+ }
968
+ // -------------------LIFECYCLE----------------------------
969
+ async init() {
970
+ this.logger.debug(`initializing board ${this.id}`);
971
+ }
972
+ async load() {
973
+ this.logger.debug(`loading board ${this.id}`);
974
+ }
975
+ };
976
+ BoardModelImpl = __decorateClass$7([
977
+ kosUiSdk.kosModel(MODEL_TYPE$7)
978
+ ], BoardModelImpl);
979
+ const Board = {
980
+ registration: {
981
+ [MODEL_TYPE$7]: {
982
+ class: BoardModelImpl,
983
+ singleton: false
984
+ }
985
+ },
986
+ type: MODEL_TYPE$7,
987
+ predicate: kosUiSdk.isKosModel(MODEL_TYPE$7),
988
+ factory: kosUiSdk.Kos.Factory.create(MODEL_TYPE$7)
989
+ };
990
+ const BoardContainer = {
991
+ registration: {
992
+ [MODEL_TYPE$9]: {
993
+ class: exports.BoardContainerModel,
994
+ singleton: true
995
+ },
996
+ ...Board.registration
997
+ },
998
+ type: MODEL_TYPE$9,
999
+ predicate: kosUiSdk.isKosModel(MODEL_TYPE$9),
1000
+ factory: kosUiSdk.Kos.Singleton.create(
1001
+ MODEL_TYPE$9
1002
+ )
1003
+ };
1004
+ var __defProp$5 = Object.defineProperty;
1005
+ var __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor;
1006
+ var __decorateClass$6 = (decorators, target, key, kind) => {
1007
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target;
1008
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
1009
+ if (decorator = decorators[i])
1010
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
1011
+ if (kind && result)
1012
+ __defProp$5(target, key, result);
1013
+ return result;
1014
+ };
1015
+ const MODEL_TYPE$6 = DispenseModelType.HolderContainer;
1016
+ const TOPIC_INSERT_START = "/kos/insertion/insert/start";
1017
+ const TOPIC_INSERT_COMPLETE = "/kos/insertion/insert/complete";
1018
+ const TOPIC_INSERT_UPDATE = "/kos/insertion/insert/update";
1019
+ const TOPIC_REMOVE = "/kos/insertion/remove";
1020
+ const TOPIC_REPLACE_LINE = "/kos/pumpEvent/replaceLine";
1021
+ const TOPIC_HOLDER_CHANGED = "/kos/handle/*";
1022
+ let HolderContainerModelImpl = class {
1023
+ constructor(modelId, _options, context) {
1024
+ __publicField(this, "id");
1025
+ __publicField(this, "holders");
1026
+ __publicField(this, "logger");
1027
+ this.id = modelId;
1028
+ this.holders = new kosUiSdk.KosModelContainer({
1029
+ indexMap: {
1030
+ nozzle: (holder) => holder.nozzlePaths,
1031
+ group: "group"
1032
+ },
1033
+ parentId: modelId,
1034
+ extensionId: ExtensionType.HolderIndex
1035
+ });
1036
+ this.logger = context.logger;
1037
+ }
1038
+ updateModel() {
1039
+ }
1040
+ handleHolderEvents(event) {
1041
+ var _a, _b, _c;
1042
+ kosUiSdk.KosLog.ifDebug(
1043
+ () => this.logger.debug("Received holder change event", JSON.stringify(event))
1044
+ );
1045
+ const holder = this.holders.getModel(event.path);
1046
+ if (holder) {
1047
+ this.logger.info(
1048
+ `Received change event for holder ${holder.path}. Updating fuel gauge data.`
1049
+ );
1050
+ holder.slice.currentVolMl = (_a = event.slice) == null ? void 0 : _a.currentVolMl;
1051
+ holder.slice.maxVolMl = (_b = event.slice) == null ? void 0 : _b.maxVolMl;
1052
+ if ((_c = event == null ? void 0 : event.container) == null ? void 0 : _c.enjoyByDate) {
1053
+ holder.enjoyByDate = new Date(event.container.enjoyByDate);
1054
+ } else {
1055
+ holder.enjoyByDate = void 0;
1056
+ }
1057
+ }
1058
+ }
1059
+ handleInsertion(data) {
1060
+ kosUiSdk.KosLog.ifDebug(
1061
+ () => this.logger.debug("Received insertion event", JSON.stringify(data))
1062
+ );
1063
+ const wrappedData = Array.isArray(data) ? data : [data];
1064
+ wrappedData.forEach((event) => {
1065
+ kosUiSdk.kosAction(() => {
1066
+ var _a, _b, _c;
1067
+ const ingredientId = event.ingredientId;
1068
+ const holder = this.holders.getModel(event.path);
1069
+ if (holder) {
1070
+ this.logger.info(
1071
+ `Received insertion event for holder ${holder.path}`
1072
+ );
1073
+ holder.updateIngredient(ingredientId);
1074
+ holder.slice.currentVolMl = (_a = event.slice) == null ? void 0 : _a.currentVolMl;
1075
+ holder.slice.maxVolMl = (_b = event.slice) == null ? void 0 : _b.maxVolMl;
1076
+ if ((_c = event == null ? void 0 : event.container) == null ? void 0 : _c.enjoyByDate) {
1077
+ holder.enjoyByDate = new Date(event.container.enjoyByDate);
1078
+ } else {
1079
+ holder.enjoyByDate = void 0;
1080
+ }
1081
+ event.pumps.forEach((pump) => {
1082
+ kosUiSdk.kosAction(() => {
1083
+ const pumpModel = holder.pumps.getModel(pump.path);
1084
+ if (pumpModel) {
1085
+ pumpModel.ingredientId = pump.ingredientId;
1086
+ pumpModel.inserted = pump.inserted;
1087
+ pumpModel.prevIngredientId = pump.prevIngredientId;
1088
+ }
1089
+ });
1090
+ });
1091
+ }
1092
+ });
1093
+ });
1094
+ }
1095
+ // -------------------ENTITY----------------------------
1096
+ };
1097
+ __decorateClass$6([
1098
+ kosUiSdk.kosChild
1099
+ ], HolderContainerModelImpl.prototype, "holders", 2);
1100
+ __decorateClass$6([
1101
+ kosUiSdk.kosTopicHandler({
1102
+ topic: TOPIC_HOLDER_CHANGED,
1103
+ websocket: true,
1104
+ condition: (event, model) => model.holders.getModel(event.path) !== void 0
1105
+ })
1106
+ ], HolderContainerModelImpl.prototype, "handleHolderEvents", 1);
1107
+ __decorateClass$6([
1108
+ kosUiSdk.kosTopicHandler({
1109
+ topic: [
1110
+ TOPIC_INSERT_START,
1111
+ TOPIC_INSERT_COMPLETE,
1112
+ TOPIC_INSERT_UPDATE,
1113
+ TOPIC_REMOVE,
1114
+ TOPIC_REPLACE_LINE
1115
+ ],
1116
+ websocket: true
1117
+ })
1118
+ ], HolderContainerModelImpl.prototype, "handleInsertion", 1);
1119
+ HolderContainerModelImpl = __decorateClass$6([
1120
+ kosUiSdk.kosModel(MODEL_TYPE$6)
1121
+ ], HolderContainerModelImpl);
1122
+ const HolderContainer = {
1123
+ registration: {
1124
+ [MODEL_TYPE$6]: {
1125
+ class: HolderContainerModelImpl,
1126
+ singleton: true
1127
+ }
1128
+ },
1129
+ type: MODEL_TYPE$6,
1130
+ predicate: kosUiSdk.isKosModel(MODEL_TYPE$6),
1131
+ factory: kosUiSdk.Kos.Singleton.create(
1132
+ MODEL_TYPE$6
1133
+ )
1134
+ };
1135
+ const Logger$1 = kosUiSdk.KosLog.createLogger({ name: "board-utils" });
1136
+ const mapAssemblyBoardToModel = async (board) => {
1137
+ const boardExtData = await kosUiSdk.KosExtensionUtils.executeDataMapperExtension({
1138
+ extension: ExtensionType.BoardMapper,
1139
+ data: board,
1140
+ contextData: {}
1141
+ });
1142
+ const { type, name, path, linked, instanceId, ...rest } = board;
1143
+ const extData = { ...rest, ...boardExtData };
1144
+ const options = {
1145
+ type,
1146
+ name,
1147
+ path,
1148
+ linked,
1149
+ instanceId,
1150
+ ...extData
1151
+ };
1152
+ const boardModel = Board.factory(board.path)(options);
1153
+ boardModel.updateModel(options);
1154
+ return boardModel;
1155
+ };
1156
+ const assemblyBoardMap = (boardContainer) => async (board) => {
1157
+ Logger$1.debug(`adding board ${board.name}`);
1158
+ const boardModel = await mapAssemblyBoardToModel(board);
1159
+ boardContainer.addModel(boardModel);
1160
+ };
1161
+ var PourState = /* @__PURE__ */ ((PourState2) => {
1162
+ PourState2["IDLE"] = "IDLE";
1163
+ PourState2["POURING"] = "POURING";
1164
+ PourState2["POUR_STARTING"] = "POUR_STARTING";
1165
+ PourState2["POUR_CANCELING"] = "POUR_CANCELING";
1166
+ return PourState2;
1167
+ })(PourState || {});
1168
+ const { URL: URL$2 } = kosUiSdk.resolveServiceUrl("PUMP_SERVICE");
1169
+ const { postModel: postModel$2, getOne: getOne$1 } = kosUiSdk.ServiceFactory.build({
1170
+ basePath: `${URL$2}/api/kos/holders`
1171
+ });
1172
+ kosUiSdk.KosLog.createLogger({
1173
+ name: "pump-service",
1174
+ group: "Services"
1175
+ });
1176
+ const sendIntent = async ({
1177
+ intent,
1178
+ pumpId,
1179
+ tracker
1180
+ }) => {
1181
+ const url = `${URL$2}/api/ext/dispense/nozzle/nozzle/pipeline/ingredient/pour/${pumpId}/${intent}`;
1182
+ const response = await postModel$2({ model: {}, urlOverride: url, tracker });
1183
+ if (response == null ? void 0 : response.data) {
1184
+ kosUiSdk.FutureManager.initiateFuture(response.data);
1185
+ }
1186
+ return response;
1187
+ };
1188
+ const getIntentVolume = async (pumpId, intent) => {
1189
+ const url = `${URL$2}/api/ext/dispense/nozzle/nozzle/pipeline/ingredient/intent/${pumpId}/${intent}/volume`;
1190
+ const response = await getOne$1({ urlOverride: url });
1191
+ if (!(response == null ? void 0 : response.data)) {
1192
+ return { volume: -1 };
1193
+ }
1194
+ return response.data;
1195
+ };
1196
+ var __defProp$4 = Object.defineProperty;
1197
+ var __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor;
1198
+ var __decorateClass$5 = (decorators, target, key, kind) => {
1199
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target;
1200
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
1201
+ if (decorator = decorators[i])
1202
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
1203
+ if (kind && result)
1204
+ __defProp$4(target, key, result);
1205
+ return result;
1206
+ };
1207
+ const MODEL_TYPE$5 = DispenseModelType.Pump;
1208
+ kosUiSdk.ExtensionManager[kosUiSdk.EXTENSION_TROUBLE_MAPPER].register(
1209
+ "pump",
1210
+ pumpTroubleResolver
1211
+ );
1212
+ let PumpModelImpl = class {
1213
+ constructor(modelId, options) {
1214
+ __publicField(this, "id");
1215
+ __publicField(this, "inserted");
1216
+ __publicField(this, "type");
1217
+ __publicField(this, "virtual");
1218
+ __publicField(this, "ingredientId");
1219
+ __publicField(this, "holderPath");
1220
+ __publicField(this, "boardPath");
1221
+ __publicField(this, "nozzlePath");
1222
+ __publicField(this, "childPump");
1223
+ __publicField(this, "name");
1224
+ __publicField(this, "path");
1225
+ __publicField(this, "prevIngredientId");
1226
+ /**
1227
+ * @kosApiLevel 12
1228
+ */
1229
+ __publicField(this, "state");
1230
+ __publicField(this, "futureHandler");
1231
+ __publicField(this, "currentState", PourState.IDLE);
1232
+ this.id = modelId;
1233
+ const {
1234
+ inserted,
1235
+ holderPath,
1236
+ boardPath,
1237
+ nozzlePath,
1238
+ name,
1239
+ path,
1240
+ childPump,
1241
+ virtual,
1242
+ prevIngredientId,
1243
+ state,
1244
+ ...rest
1245
+ } = options;
1246
+ this.inserted = inserted;
1247
+ this.type = options.type;
1248
+ this.ingredientId = options.ingredientId;
1249
+ this.holderPath = holderPath;
1250
+ this.boardPath = boardPath;
1251
+ this.nozzlePath = nozzlePath;
1252
+ this.name = name;
1253
+ this.path = path;
1254
+ this.childPump = !!childPump;
1255
+ this.virtual = !!virtual;
1256
+ this.prevIngredientId = prevIngredientId;
1257
+ this.state = state;
1258
+ Object.assign(this, rest);
1259
+ this.futureHandler = new kosUiSdk.FutureHandler(this);
1260
+ }
1261
+ updateModel(options) {
1262
+ const {
1263
+ inserted,
1264
+ holderPath,
1265
+ boardPath,
1266
+ nozzlePath,
1267
+ childPump,
1268
+ name,
1269
+ path,
1270
+ ...rest
1271
+ } = options;
1272
+ this.inserted = inserted;
1273
+ this.type = options.type;
1274
+ this.ingredientId = options.ingredientId;
1275
+ this.holderPath = holderPath;
1276
+ this.boardPath = boardPath;
1277
+ this.nozzlePath = nozzlePath;
1278
+ this.childPump = this.childPump ? this.childPump : !!childPump;
1279
+ this.name = name;
1280
+ this.path = path;
1281
+ this.prevIngredientId = options.prevIngredientId;
1282
+ Object.assign(this, rest);
1283
+ }
1284
+ // -------------------LIFECYCLE----------------------------
1285
+ get pouringState() {
1286
+ var _a;
1287
+ return ((_a = this.future) == null ? void 0 : _a.endState) || "";
1288
+ }
1289
+ get isPouring() {
1290
+ var _a;
1291
+ return !!(this.future && !((_a = this.future) == null ? void 0 : _a.endState)) || this.currentState === PourState.POUR_STARTING || this.currentState === PourState.POURING;
1292
+ }
1293
+ get canPour() {
1294
+ return !!this.ingredientId && !this.isPouring;
1295
+ }
1296
+ onFutureUpdate(future) {
1297
+ if (future.endState) {
1298
+ kosUiSdk.kosAction(() => {
1299
+ this.currentState = PourState.IDLE;
1300
+ });
1301
+ }
1302
+ }
1303
+ async cancelPour() {
1304
+ var _a;
1305
+ if (this.currentState === PourState.POURING || this.currentState === PourState.POUR_STARTING) {
1306
+ this.currentState = PourState.POUR_CANCELING;
1307
+ await ((_a = this.future) == null ? void 0 : _a.cancelFuture());
1308
+ kosUiSdk.kosAction(() => {
1309
+ this.currentState = PourState.IDLE;
1310
+ });
1311
+ } else {
1312
+ kosUiSdk.KosLog.warn(`Cannot cancel pour in state ${this.currentState}`);
1313
+ }
1314
+ }
1315
+ get future() {
1316
+ return this.futureHandler.future;
1317
+ }
1318
+ async resolveIntentVolume(intent) {
1319
+ return await getIntentVolume(this.path, intent);
1320
+ }
1321
+ async performIntent(props, tracker) {
1322
+ const intent = typeof props === "string" ? props : props.intent;
1323
+ if (!intent) {
1324
+ throw new Error("No intent provided");
1325
+ }
1326
+ try {
1327
+ if (this.currentState === PourState.IDLE) {
1328
+ this.currentState = PourState.POUR_STARTING;
1329
+ if (!tracker) {
1330
+ throw new Error("No tracker provided");
1331
+ }
1332
+ const result = await sendIntent({
1333
+ tracker,
1334
+ intent,
1335
+ pumpId: this.path
1336
+ });
1337
+ if (this.currentState === PourState.POUR_STARTING) {
1338
+ kosUiSdk.kosAction(() => {
1339
+ this.currentState = PourState.POURING;
1340
+ });
1341
+ }
1342
+ return result == null ? void 0 : result.data;
1343
+ } else {
1344
+ throw new Error(`Cannot pour in state ${this.currentState}`);
1345
+ }
1346
+ } catch (e) {
1347
+ kosUiSdk.KosLog.error(e);
1348
+ this.currentState = PourState.IDLE;
1349
+ throw e;
1350
+ }
1351
+ }
1352
+ // -------------------ENTITY----------------------------
1353
+ };
1354
+ __decorateClass$5([
1355
+ kosUiSdk.kosFuture()
1356
+ ], PumpModelImpl.prototype, "performIntent", 1);
1357
+ PumpModelImpl = __decorateClass$5([
1358
+ kosUiSdk.kosModel(MODEL_TYPE$5)
1359
+ ], PumpModelImpl);
1360
+ const Pump = {
1361
+ registration: {
1362
+ [MODEL_TYPE$5]: {
1363
+ class: PumpModelImpl,
1364
+ singleton: false
1365
+ }
1366
+ },
1367
+ type: MODEL_TYPE$5,
1368
+ predicate: kosUiSdk.isKosModel(MODEL_TYPE$5),
1369
+ factory: kosUiSdk.Kos.Factory.create(MODEL_TYPE$5)
1370
+ };
1371
+ const Logger = kosUiSdk.KosLog.createLogger({ name: "pump-utils" });
1372
+ const mapAssemblyPumpToModel = (nozzlePath, pump) => {
1373
+ const virtual = (pump.pumps ?? []).length > 1;
1374
+ const options = {
1375
+ boardPath: pump.boardPath,
1376
+ holderPath: pump.holderPath,
1377
+ ingredientId: pump.ingredientId,
1378
+ childPump: !!pump.childPump,
1379
+ virtual,
1380
+ inserted: pump.inserted,
1381
+ name: pump.name,
1382
+ path: pump.path,
1383
+ type: pump.type,
1384
+ nozzlePath,
1385
+ prevIngredientId: pump.prevIngredientId,
1386
+ state: pump.state
1387
+ };
1388
+ const pumpModel = Pump.factory(pump.path)(options);
1389
+ pumpModel.updateModel(options);
1390
+ return pumpModel;
1391
+ };
1392
+ const assemblyPumpMap = (pumpContainer) => (holderContainer) => (nozzle) => (assemblyPump) => {
1393
+ var _a;
1394
+ try {
1395
+ Logger.debug(`adding pump ${assemblyPump.name}`);
1396
+ const pump = mapAssemblyPumpToModel(nozzle.path, assemblyPump);
1397
+ pumpContainer.addModel(pump);
1398
+ const holderPath = pump.holderPath;
1399
+ const holder = holderContainer.holders.getModel(holderPath);
1400
+ holder == null ? void 0 : holder.pumps.addModel(pump);
1401
+ if (!(holder == null ? void 0 : holder.nozzlePaths.includes(nozzle.path))) {
1402
+ holder == null ? void 0 : holder.nozzlePaths.push(nozzle.path);
1403
+ }
1404
+ (_a = assemblyPump == null ? void 0 : assemblyPump.pumps) == null ? void 0 : _a.forEach((subPump) => {
1405
+ const subHolderPath = pump.holderPath;
1406
+ const subPumpData = {
1407
+ ...subPump,
1408
+ childPump: true,
1409
+ holderPath: subHolderPath,
1410
+ ingredientId: pump.ingredientId
1411
+ };
1412
+ assemblyPumpMap(pumpContainer)(holderContainer)(nozzle)(subPumpData);
1413
+ });
1414
+ } catch (error) {
1415
+ Logger.error(`Error mapping assembly pump: ${error}`);
1416
+ throw error;
1417
+ }
1418
+ };
1419
+ var __defProp$3 = Object.defineProperty;
1420
+ var __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor;
1421
+ var __decorateClass$4 = (decorators, target, key, kind) => {
1422
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target;
1423
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
1424
+ if (decorator = decorators[i])
1425
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
1426
+ if (kind && result)
1427
+ __defProp$3(target, key, result);
1428
+ return result;
1429
+ };
1430
+ const MODEL_TYPE$4 = "assembly-model";
1431
+ const CONTEXT_ASSEMBLY_DATA = "assembly-data";
1432
+ const CONTEXT_ASSEMBLY_RAW_DATA = "assembly-raw-data";
1433
+ let AssemblyModelImpl = class {
1434
+ constructor(modelId, _options, context) {
1435
+ __publicField(this, "id");
1436
+ __publicField(this, "_nozzlePaths", /* @__PURE__ */ new Set());
1437
+ __publicField(this, "troubleContainer");
1438
+ __publicField(this, "holderContainer");
1439
+ __publicField(this, "boardContainer");
1440
+ __publicField(this, "pumpContainer");
1441
+ __publicField(this, "logger");
1442
+ this.id = modelId;
1443
+ this.holderContainer = HolderContainer.factory({});
1444
+ this.boardContainer = BoardContainer.factory({});
1445
+ this.pumpContainer = PumpContainer.factory({});
1446
+ this.logger = context.logger;
1447
+ }
1448
+ updateModel(_options) {
1449
+ }
1450
+ get allHolders() {
1451
+ return this.holderContainer.holders.data;
1452
+ }
1453
+ get holderGroups() {
1454
+ return this.holderContainer.holders.getIndexKeys("group");
1455
+ }
1456
+ get nozzlePaths() {
1457
+ return Array.from(this._nozzlePaths);
1458
+ }
1459
+ getHoldersByGroup(group) {
1460
+ return this.holderContainer.holders.getIndexByKey("group", group);
1461
+ }
1462
+ getHoldersByNozzle(nozzlePath) {
1463
+ return this.holderContainer.holders.getIndexByKey("nozzle", nozzlePath);
1464
+ }
1465
+ /**
1466
+ * Returns a map of the pumps associated with each nozzle
1467
+ *
1468
+ * Can be used in conjunction with the nozzlePaths to get the pumps associated with each nozzle
1469
+ * @returns Record<string, PumpModel[]>
1470
+ */
1471
+ get pumpsByNozzle() {
1472
+ return this.pumpContainer.models.idx.byNozzle;
1473
+ }
1474
+ /**
1475
+ * Returns a list of all fo the pumps paths across the entire assembly.
1476
+ */
1477
+ get pumpPaths() {
1478
+ return this.pumpContainer.models.data.map((pump) => pump.path);
1479
+ }
1480
+ get boards() {
1481
+ return this.boardContainer.boardList;
1482
+ }
1483
+ // -------------------LIFECYCLE----------------------------
1484
+ async init() {
1485
+ this.logger.debug(`initializing assembly ${this.id}`);
1486
+ }
1487
+ async ready() {
1488
+ var _a;
1489
+ (_a = this.troubleContainer) == null ? void 0 : _a.troubles.increment();
1490
+ kosUiSdk.ExtensionManager[kosUiSdk.EXTENSION_FEATURE_FLAG_RESOLVER].execute(
1491
+ ExtensionType.AssemblyFeatureFlags,
1492
+ this
1493
+ );
1494
+ }
1495
+ async load(context) {
1496
+ this.logger.debug(`loading assembly ${this.id}`);
1497
+ const result = await getAssembly();
1498
+ if ((result == null ? void 0 : result.status) === 200) {
1499
+ const data = await kosUiSdk.KosExtensionUtils.executeDataMapperExtension({
1500
+ extension: ExtensionType.AssemblyMapper,
1501
+ data: result.data,
1502
+ contextData: {}
1503
+ });
1504
+ context.set(CONTEXT_ASSEMBLY_DATA, data);
1505
+ Object.assign(this, data);
1506
+ Object.entries(data).forEach(([key, value]) => {
1507
+ if (kosUiSdk.isKosDataModel(value)) {
1508
+ this.logger.debug(`adding child model ${key} from extension data`);
1509
+ this[kosUiSdk.ChildModels][key] = true;
1510
+ }
1511
+ });
1512
+ context.set(CONTEXT_ASSEMBLY_RAW_DATA, result.data);
1513
+ for await (const assembly of result.data.assemblies) {
1514
+ const {
1515
+ boards = [],
1516
+ holders: assemblyHolders = {},
1517
+ nozzles = [],
1518
+ core: _core,
1519
+ name,
1520
+ path: _path,
1521
+ ...rest
1522
+ } = assembly;
1523
+ this.logger.debug(`adding assembly ${name}`);
1524
+ this.logger.warn(`Assembly rest keys: ${Object.keys(rest).join(", ")}`);
1525
+ Object.keys(rest).forEach((key) => {
1526
+ var _a;
1527
+ this.logger.warn(`Enabling feature flag: ${key}`);
1528
+ kosUiSdk.KosFeatureFlags.enableFeature(key);
1529
+ context.set(`assembly-feature-${key}`, rest[key]);
1530
+ if (((_a = rest[key]["state"]) == null ? void 0 : _a["path"]) !== void 0) {
1531
+ const statePath = rest[key]["state"]["path"];
1532
+ this.logger.warn(`Feature flag ${key} state path: ${statePath}`);
1533
+ context.set(`assembly-state-path-${key}`, statePath);
1534
+ }
1535
+ });
1536
+ for await (const board of boards) {
1537
+ this.logger.debug(`adding board ${board.name}`);
1538
+ const mapper = assemblyBoardMap(this.boardContainer);
1539
+ await mapper(board);
1540
+ }
1541
+ for await (const [group, holders] of Object.entries(
1542
+ assemblyHolders ?? {}
1543
+ )) {
1544
+ for await (const holder of holders) {
1545
+ this.logger.debug(`adding holder ${holder.name}`);
1546
+ const holderModel = await mapAssemblyHolderToModel(group, holder);
1547
+ this.holderContainer.holders.addModel(holderModel);
1548
+ }
1549
+ }
1550
+ const nozzlePumpMap = assemblyPumpMap(this.pumpContainer)(
1551
+ this.holderContainer
1552
+ );
1553
+ nozzles.forEach((nozzle) => {
1554
+ this._nozzlePaths.add(nozzle.path);
1555
+ const pumpMap = nozzlePumpMap(nozzle);
1556
+ nozzle.pumps.forEach(pumpMap);
1557
+ });
1558
+ }
1559
+ }
1560
+ }
1561
+ };
1562
+ __decorateClass$4([
1563
+ kosUiSdk.kosDependency({
1564
+ modelType: "trouble-container-model"
1565
+ })
1566
+ ], AssemblyModelImpl.prototype, "troubleContainer", 2);
1567
+ __decorateClass$4([
1568
+ kosUiSdk.kosChild
1569
+ ], AssemblyModelImpl.prototype, "holderContainer", 2);
1570
+ __decorateClass$4([
1571
+ kosUiSdk.kosChild
1572
+ ], AssemblyModelImpl.prototype, "boardContainer", 2);
1573
+ __decorateClass$4([
1574
+ kosUiSdk.kosChild
1575
+ ], AssemblyModelImpl.prototype, "pumpContainer", 2);
1576
+ AssemblyModelImpl = __decorateClass$4([
1577
+ kosUiSdk.kosModel(MODEL_TYPE$4)
1578
+ ], AssemblyModelImpl);
1579
+ const Assembly = {
1580
+ registration: {
1581
+ [MODEL_TYPE$4]: {
1582
+ class: AssemblyModelImpl,
1583
+ singleton: true
1584
+ }
1585
+ },
1586
+ type: MODEL_TYPE$4,
1587
+ predicate: kosUiSdk.isKosModel(MODEL_TYPE$4),
1588
+ factory: kosUiSdk.Kos.Singleton.create(MODEL_TYPE$4)
1589
+ };
1590
+ var __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor;
1591
+ var __decorateClass$3 = (decorators, target, key, kind) => {
1592
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target;
1593
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
1594
+ if (decorator = decorators[i])
1595
+ result = decorator(result) || result;
1596
+ return result;
1597
+ };
1598
+ const MODEL_TYPE$3 = DispenseModelType.Availability;
1599
+ let AvailabilityModelImpl = class {
1600
+ constructor(modelId, options, context) {
1601
+ __publicField(this, "id");
1602
+ __publicField(this, "data");
1603
+ __publicField(this, "properties");
1604
+ __publicField(this, "available");
1605
+ __publicField(this, "visible");
1606
+ __publicField(this, "groupId");
1607
+ __publicField(this, "rawId");
1608
+ __publicField(this, "altId");
1609
+ __publicField(this, "type");
1610
+ __publicField(this, "note");
1611
+ __publicField(this, "taggedIds");
1612
+ __publicField(this, "parentId");
1613
+ __publicField(this, "logger");
1614
+ this.id = modelId;
1615
+ this.taggedIds = options.taggedIds || [];
1616
+ this.logger = context.logger;
1617
+ this.available = options.available;
1618
+ this.visible = options.visible;
1619
+ this.groupId = options.groupId;
1620
+ this.rawId = options.rawId;
1621
+ this.altId = options.altId;
1622
+ this.type = options.type;
1623
+ this.parentId = options.kosParentId;
1624
+ this.data = options.data;
1625
+ this.note = options.note;
1626
+ this.properties = options.properties || {};
1627
+ }
1628
+ updateModel(options) {
1629
+ this.taggedIds = options.taggedIds || [];
1630
+ this.available = options.available;
1631
+ this.visible = options.visible;
1632
+ this.groupId = options.groupId;
1633
+ this.rawId = options.rawId;
1634
+ this.altId = options.altId;
1635
+ this.type = options.type;
1636
+ this.data = options.data;
1637
+ }
1638
+ updateAvailability(available) {
1639
+ this.available = available;
1640
+ }
1641
+ // -------------------LIFECYCLE----------------------------
1642
+ // -------------------ENTITY----------------------------
1643
+ };
1644
+ AvailabilityModelImpl = __decorateClass$3([
1645
+ kosUiSdk.kosParentAware(),
1646
+ kosUiSdk.kosModel(MODEL_TYPE$3)
1647
+ ], AvailabilityModelImpl);
1648
+ const Availability = {
1649
+ registration: {
1650
+ [MODEL_TYPE$3]: {
1651
+ class: AvailabilityModelImpl,
1652
+ singleton: false
1653
+ }
1654
+ },
1655
+ type: MODEL_TYPE$3,
1656
+ predicate: kosUiSdk.isKosModel(MODEL_TYPE$3),
1657
+ factory: kosUiSdk.Kos.Factory.create(
1658
+ MODEL_TYPE$3
1659
+ )
1660
+ };
1661
+ const { URL: URL$1 } = kosUiSdk.resolveServiceUrl("NOZZLE_SERVICE");
1662
+ const { postModel: postModel$1, deleteModel, getOne } = kosUiSdk.ServiceFactory.build({
1663
+ basePath: `${URL$1}/api/nozzle`
1664
+ });
1665
+ const pourPourable = async (nozzleId, tracker) => {
1666
+ const response = await postModel$1({
1667
+ model: {},
1668
+ urlOverride: `${URL$1}/api/ext/dispense/nozzle/${nozzleId}/pipeline/beverage/pour`,
1669
+ ordered: true,
1670
+ tracker
1671
+ });
1672
+ if (response == null ? void 0 : response.data) {
1673
+ kosUiSdk.FutureManager.initiateFuture(response.data);
1674
+ }
1675
+ return response;
1676
+ };
1677
+ const pourNamedPourable = async (name, nozzleId, tracker) => {
1678
+ const response = await postModel$1({
1679
+ model: {},
1680
+ urlOverride: `${URL$1}/api/ext/dispense/nozzle/${nozzleId}/pipeline/beverage/fixed/${name}`,
1681
+ ordered: true,
1682
+ tracker
1683
+ });
1684
+ if (response == null ? void 0 : response.data) {
1685
+ kosUiSdk.FutureManager.initiateFuture(response.data);
1686
+ }
1687
+ return response;
1688
+ };
1689
+ const getAvailability = async (urlPrefix) => {
1690
+ const response = await getOne({
1691
+ urlOverride: `${URL$1}${urlPrefix}/pipeline/beverage/availability`
1692
+ });
1693
+ return response;
1694
+ };
1695
+ const selectPourable = async (nozzleId, payload) => {
1696
+ const response = await postModel$1({
1697
+ model: payload,
1698
+ urlOverride: `${URL$1}/api/ext/dispense/nozzle/${nozzleId}/pipeline/beverage/select`
1699
+ });
1700
+ return response;
1701
+ };
1702
+ const clearPourable = async (nozzleId) => {
1703
+ const response = await deleteModel({
1704
+ id: nozzleId,
1705
+ urlOverride: `${URL$1}/api/ext/dispense/nozzle/${nozzleId}/pipeline/beverage/select`
1706
+ });
1707
+ return response;
1708
+ };
1709
+ var __defProp$2 = Object.defineProperty;
1710
+ var __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor;
1711
+ var __decorateClass$2 = (decorators, target, key, kind) => {
1712
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target;
1713
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
1714
+ if (decorator = decorators[i])
1715
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
1716
+ if (kind && result)
1717
+ __defProp$2(target, key, result);
1718
+ return result;
1719
+ };
1720
+ const MODEL_TYPE$2 = DispenseModelType.Nozzle;
1721
+ const PROP_BEVERAGE_TOPIC_PREFIX = kosUiSdk.createPropKey(
1722
+ "beverageTopicPrefix"
1723
+ );
1724
+ const isPourAware$1 = (model) => model.onPourStart !== void 0 && model.onPourCancel !== void 0 && model.onPourProgress !== void 0;
1725
+ const TOPIC_NOZZLE_POUR_STARTED = "/kos/nozzle/pour/started";
1726
+ const TOPIC_NOZZLE_POUR_PROGRESS = "/kos/nozzle/pour/progress";
1727
+ const TOPIC_NOZZLE_POUR_CANCEL = "/kos/nozzle/pour/cancel";
1728
+ let NozzleModelImpl = class {
1729
+ constructor(modelId, options) {
1730
+ /** the unique identifier for this nozzle.*/
1731
+ __publicField(this, "id");
1732
+ __publicField(this, "path");
1733
+ __publicField(this, "name");
1734
+ __publicField(this, "_selectedBeverage");
1735
+ __publicField(this, "_selectedBrand");
1736
+ __publicField(this, "_additionalItems");
1737
+ __publicField(this, "_availabilityItems");
1738
+ __publicField(this, "futureHandler");
1739
+ __publicField(this, "beverageTopicPrefix");
1740
+ __publicField(this, "topicPrefix");
1741
+ __publicField(this, "urlPrefix");
1742
+ this.id = modelId;
1743
+ this.path = options.path;
1744
+ this.name = options.name;
1745
+ this.beverageTopicPrefix = options.beverageTopicPrefix;
1746
+ this.topicPrefix = options.topicPrefix;
1747
+ this.urlPrefix = options.urlPrefix;
1748
+ this._selectedBeverage = void 0;
1749
+ this._selectedBrand = void 0;
1750
+ this._additionalItems = [];
1751
+ this.futureHandler = new kosUiSdk.MultipleFutureHandler(this);
1752
+ this._availabilityItems = new kosUiSdk.KosModelContainer({
1753
+ indexMap: {
1754
+ byGroup: "groupId",
1755
+ byParent: "parentId"
1756
+ },
1757
+ parentId: modelId
1758
+ });
1759
+ }
1760
+ /**
1761
+ * The availability nodes that can be dispensed from this nozzle.
1762
+ * This is a subset of the availability for the entire dispenser
1763
+ * and is determined by the nodes associated with a nozzle.
1764
+ */
1765
+ get beverages() {
1766
+ return this._availabilityItems.getIndexByKey("byGroup", "beverages");
1767
+ }
1768
+ /**
1769
+ * The availability nodes that have been grouped into the "brands" group.
1770
+ *
1771
+ */
1772
+ get brands() {
1773
+ return this._availabilityItems.getIndexByKey("byGroup", "brands");
1774
+ }
1775
+ get visibleBrands() {
1776
+ return this.brands.filter((brand) => brand.visible);
1777
+ }
1778
+ get visibleBeverages() {
1779
+ return this.beverages.filter((beverage) => beverage.visible);
1780
+ }
1781
+ /**
1782
+ * A derived value that indicates if the nozzle is currently pouring a beverage.
1783
+ * @readonly
1784
+ */
1785
+ get isPouring() {
1786
+ var _a;
1787
+ return !!(this.futureHandler.getFuture() && !((_a = this.futureHandler.getFuture()) == null ? void 0 : _a.endState)) || this.currentState === PourState.POUR_STARTING || this.currentState === PourState.POURING || this.currentState === PourState.POUR_CANCELING;
1788
+ }
1789
+ /**
1790
+ * A derived value that indicates if the nozzle is currently available to pour a beverage.
1791
+ *
1792
+ * This will generally be determined by whether there is a currently selected pourable AND
1793
+ * the nozzle is not currently pouring.
1794
+ *
1795
+ * The value is observable and will change when the selected pourable changes or the nozzle
1796
+ * starts or stops pouring.
1797
+ * @readonly
1798
+ * */
1799
+ get canPour() {
1800
+ return !!this._selectedBeverage && this._selectedBeverage.available && this.currentState === PourState.IDLE;
1801
+ }
1802
+ /**
1803
+ * The selected pourable for this nozzle. Its shape is determined by the results of the
1804
+ * {@link ExtensionType.SelectedPourableMapper} extension.
1805
+ * @readonly
1806
+ *
1807
+ * */
1808
+ get selectedPourable() {
1809
+ return {
1810
+ beverage: this._selectedBeverage,
1811
+ additional: this._additionalItems
1812
+ };
1813
+ }
1814
+ get future() {
1815
+ return this.futureHandler.getFuture();
1816
+ }
1817
+ get pourProgress() {
1818
+ var _a;
1819
+ return ((_a = this.future) == null ? void 0 : _a.progress) ?? 0;
1820
+ }
1821
+ updateModel() {
1822
+ }
1823
+ // -------------------LIFECYCLE----------------------------
1824
+ setSelectedBrand(brand, _context) {
1825
+ if (_context) {
1826
+ this.logger.debug(`context is currenty being ignored when setting brand`);
1827
+ }
1828
+ this._selectedBrand = brand;
1829
+ this._selectedBeverage = void 0;
1830
+ }
1831
+ get selectedBrand() {
1832
+ return this._selectedBrand;
1833
+ }
1834
+ /**
1835
+ * Set the values used to determine the selected pourable for this nozzle.
1836
+ *
1837
+ * @param pourable The pourable to set.
1838
+ * @param pourable.beverage The beverage selected.
1839
+ * @param pourable.additional The additional items such as flavors or other items that could be incorporated
1840
+ * into the pourable.
1841
+ * */
1842
+ async setSelectedPourable({ beverage, additional, context }, forceUpdate = false) {
1843
+ if (!beverage) {
1844
+ const response2 = await clearPourable(this.name);
1845
+ if ((response2 == null ? void 0 : response2.status) !== 200) {
1846
+ throw new Error("Failed to clear pourable");
1847
+ }
1848
+ this._selectedBeverage = void 0;
1849
+ return;
1850
+ }
1851
+ if (!forceUpdate && beverage === this._selectedBeverage && kosUiSdk.arraysEqual(this._additionalItems, additional)) {
1852
+ this.logger.info("No change in selected pourable");
1853
+ return;
1854
+ }
1855
+ this._selectedBeverage = beverage;
1856
+ this._additionalItems = additional;
1857
+ let selectedPayload;
1858
+ try {
1859
+ selectedPayload = await kosUiSdk.ExtensionManager.dataMapper.executeMapper(
1860
+ ExtensionType.SelectedPourableMapper,
1861
+ {
1862
+ beverage,
1863
+ additional,
1864
+ context
1865
+ }
1866
+ );
1867
+ } catch (e) {
1868
+ this.logger.error(
1869
+ `Error executing SelectedPourableMapper, falling back to default payload. Error: ${e}`
1870
+ );
1871
+ selectedPayload = void 0;
1872
+ }
1873
+ const defaultPayload = {
1874
+ bevId: beverage.rawId
1875
+ };
1876
+ if (!selectedPayload || Object.keys(selectedPayload).length === 0) {
1877
+ this.logger.info(
1878
+ `No selected pourable mapper defined, using the default payload ${defaultPayload}`
1879
+ );
1880
+ selectedPayload = defaultPayload;
1881
+ }
1882
+ const payload = selectedPayload ?? defaultPayload;
1883
+ const response = await selectPourable(this.name, payload);
1884
+ if ((response == null ? void 0 : response.status) !== 200) {
1885
+ throw new Error("Failed to select pourable");
1886
+ }
1887
+ }
1888
+ /**
1889
+ * Utility method that will return the availability nodes that belong to the specified
1890
+ * group as defined in the dispenser beverage graph. For example, a dispenser
1891
+ * implementation may group availability nodes by Brand, Beverage, or Flavors
1892
+ *
1893
+ * @param groupId The group to filter by.
1894
+ * @returns The availability nodes that are available to be dispensed from this nozzle
1895
+ * and are in the specified group.
1896
+ * */
1897
+ getGroupAvailabilityItems(groupId) {
1898
+ return this._availabilityItems.getIndexByKey(
1899
+ "byGroup",
1900
+ groupId
1901
+ );
1902
+ }
1903
+ /**
1904
+ * Utility method that will return the availability nodes that are tagged with the specified parent id.
1905
+ *
1906
+ * This is useful when brandsets use the taggedIds property to associate nodes with a parent node. For example,
1907
+ * when organizing a brandset into brands and beverages, the brand nodes will be tagged with the beverage nodes.
1908
+ *
1909
+ * @param parentId - The parent id to filter by.
1910
+ * @returns the availability nodes that are tagged with the specified parent id.
1911
+ */
1912
+ getAvailabilityByParent(parentId) {
1913
+ return this._availabilityItems.getIndexByKey(
1914
+ "byParent",
1915
+ parentId
1916
+ );
1917
+ }
1918
+ handlePouringStart() {
1919
+ this.logger.info("Pour started");
1920
+ kosUiSdk.getAllKosCompanionModels(this).forEach((model) => {
1921
+ var _a;
1922
+ if (isPourAware$1(model)) {
1923
+ (_a = model.onPourStart) == null ? void 0 : _a.call(model);
1924
+ }
1925
+ });
1926
+ }
1927
+ handlePouringEnd() {
1928
+ this.logger.info("Pour ended");
1929
+ }
1930
+ handleCancelStart() {
1931
+ this.logger.info("Pour canceling");
1932
+ }
1933
+ handleCanceled() {
1934
+ this.logger.info("Pour canceled");
1935
+ kosUiSdk.getAllKosCompanionModels(this).forEach((model) => {
1936
+ var _a;
1937
+ if (isPourAware$1(model)) {
1938
+ (_a = model.onPourCancel) == null ? void 0 : _a.call(model);
1939
+ }
1940
+ });
1941
+ const evt = {
1942
+ nozzleId: this.id
1943
+ };
1944
+ kosUiSdk.EventBus.publish(TOPIC_NOZZLE_POUR_CANCEL, evt);
1945
+ }
1946
+ // ============================================================================
1947
+ // Future Lifecycle Handler
1948
+ // ============================================================================
1949
+ onFutureUpdate(future) {
1950
+ const companions = kosUiSdk.getAllKosCompanionModels(this);
1951
+ companions.forEach((model) => {
1952
+ if (isPourAware$1(model)) {
1953
+ model.onPourProgress(future);
1954
+ }
1955
+ });
1956
+ const evt = {
1957
+ nozzleId: this.id,
1958
+ progress: future.progress,
1959
+ status: future.status,
1960
+ clientData: future.clientData,
1961
+ futureId: future.futureId,
1962
+ remainingTimeMs: future.remainingTimeMs,
1963
+ endState: future.endState,
1964
+ reason: future.reason,
1965
+ timeRemaining: future.timeRemaining
1966
+ };
1967
+ kosUiSdk.EventBus.publish(TOPIC_NOZZLE_POUR_PROGRESS, evt);
1968
+ if (future.endState) {
1969
+ kosUiSdk.kosAction(() => {
1970
+ if (this.currentState === PourState.POURING) {
1971
+ this.transition("POUR_COMPLETED");
1972
+ }
1973
+ });
1974
+ }
1975
+ }
1976
+ // Inherits throwOnInvalid: false from class
1977
+ async pour(tracker) {
1978
+ var _a;
1979
+ try {
1980
+ this.transition("START_POUR");
1981
+ if (!tracker) {
1982
+ throw new Error("No tracker provided");
1983
+ }
1984
+ const result = await pourPourable(this.name, tracker);
1985
+ this.transition("POUR_ACTIVE");
1986
+ const evt = {
1987
+ nozzleId: this.id,
1988
+ type: "free"
1989
+ };
1990
+ kosUiSdk.EventBus.publish(TOPIC_NOZZLE_POUR_STARTED, evt);
1991
+ if ((_a = result == null ? void 0 : result.data) == null ? void 0 : _a.endState) {
1992
+ this.transition("POUR_COMPLETED");
1993
+ }
1994
+ return result;
1995
+ } catch (e) {
1996
+ this.logger.error(e);
1997
+ if (this.currentState !== PourState.IDLE) {
1998
+ this.transition("POUR_COMPLETED");
1999
+ }
2000
+ throw e;
2001
+ }
2002
+ }
2003
+ // Inherits throwOnInvalid: false from class
2004
+ async fixedPour(name, tracker) {
2005
+ var _a;
2006
+ try {
2007
+ this.transition("START_POUR");
2008
+ if (!tracker) {
2009
+ throw new Error("No tracker provided");
2010
+ }
2011
+ const result = await pourNamedPourable(name, this.name, tracker);
2012
+ this.transition("POUR_ACTIVE");
2013
+ const evt = {
2014
+ nozzleId: this.id,
2015
+ type: "fixed"
2016
+ };
2017
+ kosUiSdk.EventBus.publish(TOPIC_NOZZLE_POUR_STARTED, evt);
2018
+ if ((_a = result == null ? void 0 : result.data) == null ? void 0 : _a.endState) {
2019
+ this.transition("POUR_COMPLETED");
2020
+ }
2021
+ return result;
2022
+ } catch (e) {
2023
+ this.logger.error(e);
2024
+ if (this.currentState !== PourState.IDLE) {
2025
+ this.transition("POUR_COMPLETED");
2026
+ }
2027
+ throw e;
2028
+ }
2029
+ }
2030
+ // Inherits throwOnInvalid: false - silently ignore if already idle
2031
+ async cancelPour() {
2032
+ var _a;
2033
+ this.transition("CANCEL_POUR");
2034
+ await ((_a = this.futureHandler.getFuture()) == null ? void 0 : _a.cancelFuture());
2035
+ this.transition("POUR_CANCELED");
2036
+ }
2037
+ updateGroupMembers() {
2038
+ this._availabilityItems.data.forEach((item) => {
2039
+ const taggedIds = item.taggedIds || [];
2040
+ taggedIds.forEach((taggedId) => {
2041
+ const childItem = this._availabilityItems.data.find(
2042
+ (beverage) => beverage.rawId === taggedId
2043
+ );
2044
+ if (childItem && childItem.parentId !== item.id) {
2045
+ childItem.parentId = item.id;
2046
+ this._availabilityItems.updateModel(childItem);
2047
+ }
2048
+ });
2049
+ });
2050
+ }
2051
+ async reload() {
2052
+ this.logger.info(`reloading nozzle ${this.id}`);
2053
+ const context = kosUiSdk.KosContextManager.getContext(this.id);
2054
+ (context == null ? void 0 : context.get(ExtensionType.AvailabilityLoader)) || {};
2055
+ const availability = await getAvailability(this.urlPrefix);
2056
+ if ((availability == null ? void 0 : availability.status) !== 200 || !(availability == null ? void 0 : availability.data)) {
2057
+ this.logger.error("Failed to load nozzle availability");
2058
+ return;
2059
+ }
2060
+ const update = availability == null ? void 0 : availability.data;
2061
+ if (update) {
2062
+ await this.updateAvailability(update);
2063
+ }
2064
+ }
2065
+ /** @internal */
2066
+ async load(context) {
2067
+ var _a, _b;
2068
+ this.logger.debug(`loading nozzle ${this.id}`);
2069
+ const availability = await getAvailability(this.urlPrefix);
2070
+ if ((availability == null ? void 0 : availability.status) !== 200) {
2071
+ throw new Error("Failed to load nozzle availability");
2072
+ }
2073
+ const beverageContext = await kosUiSdk.ExtensionManager.loader.executeLoader(
2074
+ ExtensionType.AvailabilityLoader,
2075
+ {}
2076
+ );
2077
+ context == null ? void 0 : context.set(ExtensionType.AvailabilityLoader, beverageContext);
2078
+ context == null ? void 0 : context.set(Nozzle.type, this);
2079
+ for (const group of Object.keys((_a = availability.data) == null ? void 0 : _a.groups) || []) {
2080
+ for (const beverageData of ((_b = availability.data) == null ? void 0 : _b.groups[group]) || []) {
2081
+ const extensionData = await kosUiSdk.ExtensionManager.dataMapper.executeMapper(
2082
+ ExtensionType.AvailabilityMapper,
2083
+ { ...beverageData, groupId: group },
2084
+ beverageContext
2085
+ );
2086
+ const beverageOptions = {
2087
+ ...beverageData,
2088
+ note: beverageData.note ?? void 0,
2089
+ kosParentId: this.id,
2090
+ rawId: beverageData.id,
2091
+ groupId: group,
2092
+ data: extensionData,
2093
+ properties: beverageData.properties || {}
2094
+ };
2095
+ const beverage = Availability.factory(
2096
+ `${this.id}-${group}-${beverageData.id}`
2097
+ )(beverageOptions);
2098
+ this._availabilityItems.addModel(beverage);
2099
+ }
2100
+ }
2101
+ this.updateGroupMembers();
2102
+ }
2103
+ async updateAvailability(update) {
2104
+ const context = kosUiSdk.KosContextManager.getContext(this.id);
2105
+ const beverageContext = (context == null ? void 0 : context.get(ExtensionType.AvailabilityLoader)) || {};
2106
+ if (update.rebuild) {
2107
+ for (const group of Object.keys(update == null ? void 0 : update.groups) || []) {
2108
+ const deletedBeverages = this._availabilityItems.getIndexByKey("group", group).filter(
2109
+ (beverage) => !update.groups[group].find(
2110
+ (b) => `${this.id}-${group}-${b.id}` === beverage.id
2111
+ )
2112
+ );
2113
+ deletedBeverages.forEach((beverage) => {
2114
+ this._availabilityItems.removeModel(beverage.id);
2115
+ kosUiSdk.destroyKosModel(beverage);
2116
+ });
2117
+ for (const beverageData of (update == null ? void 0 : update.groups[group]) || []) {
2118
+ const extensionData = await kosUiSdk.ExtensionManager.dataMapper.executeMapper(
2119
+ ExtensionType.AvailabilityMapper,
2120
+ { ...beverageData, groupId: group },
2121
+ beverageContext
2122
+ );
2123
+ const beverageOptions = {
2124
+ ...beverageData,
2125
+ note: beverageData.note ?? void 0,
2126
+ kosParentId: this.id,
2127
+ groupId: group,
2128
+ rawId: beverageData.id,
2129
+ data: extensionData,
2130
+ taggedIds: beverageData.taggedIds,
2131
+ properties: beverageData.properties || {}
2132
+ };
2133
+ const existing = this._availabilityItems.getModel(
2134
+ `${this.id}-${group}-${beverageData.id}`
2135
+ );
2136
+ if (existing) {
2137
+ existing.updateModel(beverageOptions);
2138
+ } else {
2139
+ const beverage = Availability.factory(
2140
+ `${this.id}-${group}-${beverageData.id}`
2141
+ )(beverageOptions);
2142
+ this._availabilityItems.addModel(beverage);
2143
+ }
2144
+ }
2145
+ }
2146
+ } else {
2147
+ for (const group of Object.keys(update == null ? void 0 : update.groups) || []) {
2148
+ for (const beverageData of (update == null ? void 0 : update.groups[group]) || []) {
2149
+ const extensionData = await kosUiSdk.ExtensionManager.dataMapper.executeMapper(
2150
+ ExtensionType.AvailabilityMapper,
2151
+ { ...beverageData, groupId: group },
2152
+ beverageContext
2153
+ );
2154
+ const beverageOptions = {
2155
+ ...beverageData,
2156
+ note: beverageData.note ?? void 0,
2157
+ kosParentId: this.id,
2158
+ groupId: group,
2159
+ rawId: beverageData.id,
2160
+ data: extensionData,
2161
+ type: beverageData.type,
2162
+ taggedIds: beverageData.taggedIds,
2163
+ properties: beverageData.properties || {}
2164
+ };
2165
+ const existing = this._availabilityItems.getModel(
2166
+ `${this.id}-${group}-${beverageData.id}`
2167
+ );
2168
+ if (existing) {
2169
+ existing.updateModel(beverageOptions);
2170
+ }
2171
+ }
2172
+ }
2173
+ }
2174
+ this.updateGroupMembers();
2175
+ }
2176
+ // -------------------ENTITY----------------------------
2177
+ };
2178
+ __decorateClass$2([
2179
+ kosUiSdk.kosChild
2180
+ ], NozzleModelImpl.prototype, "_availabilityItems", 2);
2181
+ __decorateClass$2([
2182
+ kosUiSdk.kosStateEntry(PourState.POURING)
2183
+ ], NozzleModelImpl.prototype, "handlePouringStart", 1);
2184
+ __decorateClass$2([
2185
+ kosUiSdk.kosStateExit(PourState.POURING)
2186
+ ], NozzleModelImpl.prototype, "handlePouringEnd", 1);
2187
+ __decorateClass$2([
2188
+ kosUiSdk.kosStateEntry(PourState.POUR_CANCELING)
2189
+ ], NozzleModelImpl.prototype, "handleCancelStart", 1);
2190
+ __decorateClass$2([
2191
+ kosUiSdk.kosStateExit(PourState.POUR_CANCELING)
2192
+ ], NozzleModelImpl.prototype, "handleCanceled", 1);
2193
+ __decorateClass$2([
2194
+ kosUiSdk.kosFuture(),
2195
+ kosUiSdk.kosStateGuard({ allowedStates: [PourState.IDLE] })
2196
+ ], NozzleModelImpl.prototype, "pour", 1);
2197
+ __decorateClass$2([
2198
+ kosUiSdk.kosFuture(),
2199
+ kosUiSdk.kosStateGuard({ allowedStates: [PourState.IDLE] })
2200
+ ], NozzleModelImpl.prototype, "fixedPour", 1);
2201
+ __decorateClass$2([
2202
+ kosUiSdk.kosStateGuard({
2203
+ allowedStates: [PourState.POUR_STARTING, PourState.POURING]
2204
+ })
2205
+ ], NozzleModelImpl.prototype, "cancelPour", 1);
2206
+ __decorateClass$2([
2207
+ kosUiSdk.kosTopicHandler({
2208
+ topic: `${PROP_BEVERAGE_TOPIC_PREFIX}/availability`,
2209
+ websocket: true
2210
+ })
2211
+ ], NozzleModelImpl.prototype, "updateAvailability", 1);
2212
+ NozzleModelImpl = __decorateClass$2([
2213
+ kosUiSdk.kosModel({ modelTypeId: MODEL_TYPE$2, singleton: false }),
2214
+ kosUiSdk.kosLoggerAware(),
2215
+ kosUiSdk.kosStateMachine(
2216
+ {
2217
+ initial: PourState.IDLE,
2218
+ initializeAt: kosUiSdk.DependencyLifecycle.READY,
2219
+ states: {
2220
+ [PourState.IDLE]: {
2221
+ on: {
2222
+ START_POUR: PourState.POUR_STARTING
2223
+ }
2224
+ },
2225
+ [PourState.POUR_STARTING]: {
2226
+ on: {
2227
+ POUR_ACTIVE: PourState.POURING,
2228
+ CANCEL_POUR: PourState.POUR_CANCELING,
2229
+ POUR_COMPLETED: PourState.IDLE
2230
+ }
2231
+ },
2232
+ [PourState.POURING]: {
2233
+ on: {
2234
+ CANCEL_POUR: PourState.POUR_CANCELING,
2235
+ POUR_COMPLETED: PourState.IDLE
2236
+ }
2237
+ },
2238
+ [PourState.POUR_CANCELING]: {
2239
+ on: {
2240
+ POUR_CANCELED: PourState.IDLE
2241
+ }
2242
+ }
2243
+ }
2244
+ },
2245
+ {
2246
+ trackHistory: false,
2247
+ throwOnInvalid: false
2248
+ // Gracefully ignore invalid state calls (expected runtime scenarios)
2249
+ }
2250
+ )
2251
+ ], NozzleModelImpl);
2252
+ const Nozzle = {
2253
+ registration: {
2254
+ [MODEL_TYPE$2]: {
2255
+ class: NozzleModelImpl,
2256
+ singleton: false
2257
+ }
2258
+ },
2259
+ type: MODEL_TYPE$2,
2260
+ predicate: kosUiSdk.isKosModel(MODEL_TYPE$2),
2261
+ factory: kosUiSdk.Kos.Factory.create(MODEL_TYPE$2)
2262
+ };
2263
+ var __defProp$1 = Object.defineProperty;
2264
+ var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
2265
+ var __decorateClass$1 = (decorators, target, key, kind) => {
2266
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target;
2267
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
2268
+ if (decorator = decorators[i])
2269
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
2270
+ if (kind && result)
2271
+ __defProp$1(target, key, result);
2272
+ return result;
2273
+ };
2274
+ const MODEL_TYPE$1 = "device-assembly-model";
2275
+ let DeviceAssemblyModelImpl = class {
2276
+ constructor(modelId, _options, context) {
2277
+ __publicField(this, "id");
2278
+ __publicField(this, "deviceNozzles");
2279
+ __publicField(this, "logger");
2280
+ this.id = modelId;
2281
+ this.logger = context.logger;
2282
+ this.deviceNozzles = new kosUiSdk.KosModelContainer();
2283
+ }
2284
+ // -------------------LIFECYCLE----------------------------
2285
+ async init() {
2286
+ this.logger.debug(`initializing device-assembly ${this.id}`);
2287
+ }
2288
+ getNozzle(path) {
2289
+ return this.deviceNozzles.getModel(path);
2290
+ }
2291
+ get nozzlePaths() {
2292
+ return this.deviceNozzles.data.map((nozzle) => nozzle.path);
2293
+ }
2294
+ async load() {
2295
+ this.logger.debug(`loading device-assembly ${this.id}`);
2296
+ const result = await getAssembly();
2297
+ if ((result == null ? void 0 : result.status) === 200) {
2298
+ const nozzles = result.data.assemblies.map((assembly) => assembly.nozzles ?? []).flat();
2299
+ nozzles.forEach((nozzleData) => {
2300
+ var _a;
2301
+ const nozzleId = nozzleData.path;
2302
+ const beverageTopicPrefix = ((_a = nozzleData.pipelines.find((pipeline) => pipeline.name === "beverage")) == null ? void 0 : _a.topicPrefix) || "";
2303
+ const nozzle = Nozzle.factory(nozzleId)({
2304
+ path: nozzleData.path,
2305
+ name: nozzleData.name,
2306
+ urlPrefix: nozzleData.urlPrefix,
2307
+ topicPrefix: nozzleData.topicPrefix,
2308
+ beverageTopicPrefix
2309
+ });
2310
+ this.deviceNozzles.addModel(nozzle);
2311
+ });
2312
+ }
2313
+ }
2314
+ };
2315
+ __decorateClass$1([
2316
+ kosUiSdk.kosChild
2317
+ ], DeviceAssemblyModelImpl.prototype, "deviceNozzles", 2);
2318
+ DeviceAssemblyModelImpl = __decorateClass$1([
2319
+ kosUiSdk.kosModel(MODEL_TYPE$1)
2320
+ ], DeviceAssemblyModelImpl);
2321
+ const DeviceAssembly = new kosUiSdk.SingletonKosModelRegistrationFactory({
2322
+ class: DeviceAssemblyModelImpl,
2323
+ type: MODEL_TYPE$1
2324
+ });
2325
+ const { URL } = kosUiSdk.resolveServiceUrl("GENERIC_POUR_SERVICE");
2326
+ const { postModel } = kosUiSdk.ServiceFactory.build({
2327
+ basePath: `${URL}/api/nozzle`
2328
+ });
2329
+ const pourOnTarget = async (path, tracker) => {
2330
+ const response = await postModel({
2331
+ model: {},
2332
+ urlOverride: `${URL}${path}`,
2333
+ ordered: true,
2334
+ tracker
2335
+ });
2336
+ if (response == null ? void 0 : response.data) {
2337
+ kosUiSdk.FutureManager.initiateFuture(response.data);
2338
+ }
2339
+ return response;
2340
+ };
2341
+ var __defProp2 = Object.defineProperty;
2342
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
2343
+ var __decorateClass = (decorators, target, key, kind) => {
2344
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
2345
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
2346
+ if (decorator = decorators[i])
2347
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
2348
+ if (kind && result)
2349
+ __defProp2(target, key, result);
2350
+ return result;
2351
+ };
2352
+ const MODEL_TYPE = "generic-pour-model";
2353
+ const TOPIC_GENERIC_POUR_STARTED = "/kos/generic/pour/started";
2354
+ const TOPIC_GENERIC_POUR_PROGRESS = "/kos/generic/pour/progress";
2355
+ const TOPIC_GENERIC_POUR_CANCEL = "/kos/generic/pour/cancel";
2356
+ const isPourAware = (model) => model.onPourStart !== void 0 && model.onPourCancel !== void 0 && model.onPourProgress !== void 0;
2357
+ let GenericPourModelImpl = class {
2358
+ constructor(modelId, options) {
2359
+ __publicField(this, "id");
2360
+ /**
2361
+ * @kosApiLevel 5
2362
+ */
2363
+ __publicField(this, "servicePathFactory");
2364
+ __publicField(this, "pourType");
2365
+ /**
2366
+ * @kosApiLevel 5
2367
+ */
2368
+ __publicField(this, "selectedId");
2369
+ __publicField(this, "state");
2370
+ this.id = modelId;
2371
+ this.futureHandler = new kosUiSdk.FutureHandler(this);
2372
+ this.servicePathFactory = options.servicePathFactory;
2373
+ this.pourType = options.pourType || "free";
2374
+ this.selectedId = options.selectedId;
2375
+ this.state = kosUiSdk.ObservableData(options.initialData || {});
2376
+ }
2377
+ get servicePath() {
2378
+ if (!this.selectedId) {
2379
+ return "";
2380
+ }
2381
+ return this.servicePathFactory(this.selectedId, this.state);
2382
+ }
2383
+ /**
2384
+ * @kosApiLevel 12
2385
+ */
2386
+ updateContextData(key, value) {
2387
+ this.state[key] = value;
2388
+ }
2389
+ /**
2390
+ * @kosApiLevel 12
2391
+ */
2392
+ removeContextData(key) {
2393
+ delete this.state[key];
2394
+ }
2395
+ /**
2396
+ * @kosApiLevel 12
2397
+ */
2398
+ clearContextData() {
2399
+ this.state = kosUiSdk.ObservableData();
2400
+ }
2401
+ /**
2402
+ * @kosApiLevel 14
2403
+ */
2404
+ updateModel(options) {
2405
+ if (options.pourType) {
2406
+ this.pourType = options.pourType;
2407
+ }
2408
+ if (options.initialData) {
2409
+ this.state.setValues(options.initialData);
2410
+ }
2411
+ }
2412
+ handlePouringStart() {
2413
+ this.logger.info("Pour started");
2414
+ kosUiSdk.getAllKosCompanionModels(this).forEach((model) => {
2415
+ var _a;
2416
+ if (isPourAware(model)) {
2417
+ (_a = model.onPourStart) == null ? void 0 : _a.call(model);
2418
+ }
2419
+ });
2420
+ const evt = {
2421
+ pourTarget: this.id,
2422
+ type: this.pourType
2423
+ };
2424
+ kosUiSdk.EventBus.publish(TOPIC_GENERIC_POUR_STARTED, evt);
2425
+ }
2426
+ handlePouringEnd() {
2427
+ this.logger.info("Pour ended");
2428
+ }
2429
+ handleCancelStart() {
2430
+ this.logger.info("Pour canceling");
2431
+ }
2432
+ handleCanceled() {
2433
+ this.logger.info("Pour canceled");
2434
+ kosUiSdk.getAllKosCompanionModels(this).forEach((model) => {
2435
+ var _a;
2436
+ if (isPourAware(model)) {
2437
+ (_a = model.onPourCancel) == null ? void 0 : _a.call(model);
2438
+ }
2439
+ });
2440
+ const evt = {
2441
+ pourTarget: this.id
2442
+ };
2443
+ kosUiSdk.EventBus.publish(TOPIC_GENERIC_POUR_CANCEL, evt);
2444
+ }
2445
+ // Inherits throwOnInvalid: false from class
2446
+ async pour(tracker) {
2447
+ var _a;
2448
+ try {
2449
+ this.transition("START_POUR");
2450
+ if (!tracker) {
2451
+ throw new Error("No tracker provided");
2452
+ }
2453
+ const result = await pourOnTarget(this.servicePath, tracker);
2454
+ this.transition("POUR_ACTIVE");
2455
+ if ((_a = result == null ? void 0 : result.data) == null ? void 0 : _a.endState) {
2456
+ this.transition("POUR_COMPLETED");
2457
+ }
2458
+ return result;
2459
+ } catch (e) {
2460
+ this.logger.error(e);
2461
+ if (this.currentState !== PourState.IDLE) {
2462
+ this.transition("POUR_COMPLETED");
2463
+ }
2464
+ throw e;
2465
+ }
2466
+ }
2467
+ // Inherits throwOnInvalid: false - silently ignore if already idle
2468
+ async cancelPour() {
2469
+ var _a;
2470
+ this.transition("CANCEL_POUR");
2471
+ await ((_a = this.futureHandler.getFuture()) == null ? void 0 : _a.cancelFuture());
2472
+ this.transition("POUR_CANCELED");
2473
+ }
2474
+ // ============================================================================
2475
+ // Computed Properties
2476
+ // ============================================================================
2477
+ /**
2478
+ * A derived value that indicates if the nozzle is currently pouring a beverage.
2479
+ * @readonly
2480
+ */
2481
+ get isPouring() {
2482
+ var _a;
2483
+ return !!(this.future && !((_a = this.future) == null ? void 0 : _a.endState)) || this.currentState === PourState.POUR_STARTING || this.currentState === PourState.POURING || this.currentState === PourState.POUR_CANCELING;
2484
+ }
2485
+ /**
2486
+ * A derived value that indicates if the pour target is currently available to pour a beverage.
2487
+ *
2488
+ * Generally this means that the pour target is currently idle and not in the process of pouring,
2489
+ * initiating a pour, or canceling a pour.
2490
+ * The value is observable and will change when the selected pourable changes or the pour target
2491
+ * starts or stops pouring.
2492
+ * @readonly
2493
+ */
2494
+ get canPour() {
2495
+ return this.currentState === PourState.IDLE;
2496
+ }
2497
+ get pourProgress() {
2498
+ return this.progress ?? 0;
2499
+ }
2500
+ // ============================================================================
2501
+ // Future Lifecycle Handler
2502
+ // ============================================================================
2503
+ onFutureUpdate(future) {
2504
+ kosUiSdk.getAllKosCompanionModels(this).forEach((model) => {
2505
+ if (isPourAware(model)) {
2506
+ model.onPourProgress(future);
2507
+ }
2508
+ });
2509
+ const evt = {
2510
+ pourTarget: this.id,
2511
+ progress: future.progress,
2512
+ status: future.status,
2513
+ clientData: future.clientData,
2514
+ futureId: future.futureId,
2515
+ remainingTimeMs: future.remainingTimeMs,
2516
+ endState: future.endState,
2517
+ reason: future.reason,
2518
+ timeRemaining: future.timeRemaining
2519
+ };
2520
+ kosUiSdk.EventBus.publish(TOPIC_GENERIC_POUR_PROGRESS, evt);
2521
+ if (future.endState) {
2522
+ kosUiSdk.kosAction(() => {
2523
+ if (this.currentState === PourState.POURING) {
2524
+ this.transition("POUR_COMPLETED");
2525
+ }
2526
+ });
2527
+ }
2528
+ }
2529
+ };
2530
+ __decorateClass([
2531
+ kosUiSdk.kosStateEntry(PourState.POURING)
2532
+ ], GenericPourModelImpl.prototype, "handlePouringStart", 1);
2533
+ __decorateClass([
2534
+ kosUiSdk.kosStateExit(PourState.POURING)
2535
+ ], GenericPourModelImpl.prototype, "handlePouringEnd", 1);
2536
+ __decorateClass([
2537
+ kosUiSdk.kosStateEntry(PourState.POUR_CANCELING)
2538
+ ], GenericPourModelImpl.prototype, "handleCancelStart", 1);
2539
+ __decorateClass([
2540
+ kosUiSdk.kosStateExit(PourState.POUR_CANCELING)
2541
+ ], GenericPourModelImpl.prototype, "handleCanceled", 1);
2542
+ __decorateClass([
2543
+ kosUiSdk.kosFuture(),
2544
+ kosUiSdk.kosStateGuard({ allowedStates: [PourState.IDLE] })
2545
+ ], GenericPourModelImpl.prototype, "pour", 1);
2546
+ __decorateClass([
2547
+ kosUiSdk.kosStateGuard({
2548
+ allowedStates: [PourState.POUR_STARTING, PourState.POURING]
2549
+ })
2550
+ ], GenericPourModelImpl.prototype, "cancelPour", 1);
2551
+ GenericPourModelImpl = __decorateClass([
2552
+ kosUiSdk.kosModel(MODEL_TYPE),
2553
+ kosUiSdk.kosLoggerAware(),
2554
+ kosUiSdk.kosFutureAware(),
2555
+ kosUiSdk.kosStateMachine(
2556
+ {
2557
+ initial: PourState.IDLE,
2558
+ initializeAt: kosUiSdk.DependencyLifecycle.READY,
2559
+ states: {
2560
+ [PourState.IDLE]: {
2561
+ on: {
2562
+ START_POUR: PourState.POUR_STARTING
2563
+ }
2564
+ },
2565
+ [PourState.POUR_STARTING]: {
2566
+ on: {
2567
+ POUR_ACTIVE: PourState.POURING,
2568
+ CANCEL_POUR: PourState.POUR_CANCELING,
2569
+ POUR_COMPLETED: PourState.IDLE
2570
+ }
2571
+ },
2572
+ [PourState.POURING]: {
2573
+ on: {
2574
+ CANCEL_POUR: PourState.POUR_CANCELING,
2575
+ POUR_COMPLETED: PourState.IDLE
2576
+ }
2577
+ },
2578
+ [PourState.POUR_CANCELING]: {
2579
+ on: {
2580
+ POUR_CANCELED: PourState.IDLE
2581
+ }
2582
+ }
2583
+ }
2584
+ },
2585
+ {
2586
+ trackHistory: false,
2587
+ throwOnInvalid: false
2588
+ // Gracefully ignore invalid state calls (expected runtime scenarios)
2589
+ }
2590
+ )
2591
+ ], GenericPourModelImpl);
2592
+ const GenericPour = new kosUiSdk.KosModelRegistrationFactory({
2593
+ class: GenericPourModelImpl,
2594
+ type: MODEL_TYPE
2595
+ });
2596
+ const kosModels = {
2597
+ ...IngredientContainer.registration,
2598
+ ...Ingredient.registration,
2599
+ ...HolderContainer.registration,
2600
+ ...Holder.registration,
2601
+ ...Nozzle.registration,
2602
+ ...Pump.registration,
2603
+ ...PumpContainer.registration,
2604
+ ...Availability.registration,
2605
+ ...Assembly.registration,
2606
+ ...BoardContainer.registration
2607
+ };
2608
+ const registerDispenseModels = (root) => () => {
2609
+ kosUiSdk.registerCoreModels(root)();
2610
+ DeviceAssembly.register();
2611
+ Object.keys(kosModels).forEach((key) => {
2612
+ const model = kosModels[key];
2613
+ kosUiSdk.registerLegacyModel(root)(key, model);
2614
+ });
2615
+ kosUiSdk.ExtensionManager[kosUiSdk.EXTENSION_TROUBLE_DATA_MAPPER].register(
2616
+ "FirmwareUpdateInProgressTrouble",
2617
+ async (trouble) => {
2618
+ var _a;
2619
+ if ((_a = trouble.data) == null ? void 0 : _a.deviceId) {
2620
+ const { model: assemblyModel } = kosUiSdk.getKosModelSync(
2621
+ Assembly.type
2622
+ );
2623
+ if (assemblyModel) {
2624
+ const boardModel = assemblyModel.boards.find(
2625
+ (b) => b.id === trouble.data.deviceId
2626
+ ) ? kosUiSdk.getKosModelSync(trouble.data.deviceId).model : void 0;
2627
+ return {
2628
+ devices: boardModel ? boardModel.name : ""
2629
+ };
2630
+ }
2631
+ }
2632
+ return {};
2633
+ }
2634
+ );
2635
+ return {
2636
+ preload: kosUiSdk.RegistrationManager.model.preloadModel(root),
2637
+ model: kosUiSdk.RegistrationManager.model.register(root),
2638
+ companion: kosUiSdk.RegistrationManager.companion.register(root),
2639
+ legacy: kosUiSdk.RegistrationManager.model.registerLegacyModel(root)
2640
+ };
2641
+ };
2642
+ const _KosModelRegistry = {
2643
+ ...kosUiSdk.KosModelRegistry
2644
+ };
2645
+ _KosModelRegistry.dispense = {
2646
+ models: registerDispenseModels(_KosModelRegistry)
2647
+ };
2648
+ _KosModelRegistry.preload = kosUiSdk.RegistrationManager.model.preloadModel(_KosModelRegistry);
2649
+ _KosModelRegistry.model = kosUiSdk.RegistrationManager.model.register(_KosModelRegistry);
2650
+ _KosModelRegistry.companion = kosUiSdk.RegistrationManager.companion.register(_KosModelRegistry);
2651
+ _KosModelRegistry.legacy = kosUiSdk.RegistrationManager.model.registerLegacyModel(_KosModelRegistry);
2652
+ const KosModelRegistry = _KosModelRegistry;
2653
+ exports.Assembly = Assembly;
2654
+ exports.Availability = Availability;
2655
+ exports.Board = Board;
2656
+ exports.BoardContainer = BoardContainer;
2657
+ exports.CONTEXT_ASSEMBLY_DATA = CONTEXT_ASSEMBLY_DATA;
2658
+ exports.CONTEXT_ASSEMBLY_RAW_DATA = CONTEXT_ASSEMBLY_RAW_DATA;
2659
+ exports.DeviceAssembly = DeviceAssembly;
2660
+ exports.DispenseModelType = DispenseModelType;
2661
+ exports.ExtensionType = ExtensionType;
2662
+ exports.GenericPour = GenericPour;
2663
+ exports.Holder = Holder;
2664
+ exports.HolderContainer = HolderContainer;
2665
+ exports.Ingredient = Ingredient;
2666
+ exports.IngredientContainer = IngredientContainer;
2667
+ exports.KosModelRegistry = KosModelRegistry;
2668
+ exports.Nozzle = Nozzle;
2669
+ exports.PourState = PourState;
2670
+ exports.Pump = Pump;
2671
+ exports.PumpContainer = PumpContainer;
2672
+ exports.PumpIndex = PumpIndex;
2673
+ exports.TOPIC_BOARD_LINKED = TOPIC_BOARD_LINKED;
2674
+ exports.TOPIC_BOARD_UNLINKED = TOPIC_BOARD_UNLINKED;
2675
+ exports.TOPIC_GENERIC_POUR_CANCEL = TOPIC_GENERIC_POUR_CANCEL;
2676
+ exports.TOPIC_GENERIC_POUR_PROGRESS = TOPIC_GENERIC_POUR_PROGRESS;
2677
+ exports.TOPIC_GENERIC_POUR_STARTED = TOPIC_GENERIC_POUR_STARTED;
2678
+ exports.addAssignment = addAssignment;
2679
+ exports.assignHolderIngredient = assignHolderIngredient;
2680
+ exports.clearPourable = clearPourable;
2681
+ exports.deleteAssignment = deleteAssignment;
2682
+ exports.getAssembly = getAssembly;
2683
+ exports.getAssignments = getAssignments;
2684
+ exports.getAvailability = getAvailability;
2685
+ exports.getHolders = getHolders;
2686
+ exports.getIngredients = getIngredients;
2687
+ exports.getIntentVolume = getIntentVolume;
2688
+ exports.kosModels = kosModels;
2689
+ exports.pourNamedPourable = pourNamedPourable;
2690
+ exports.pourOnTarget = pourOnTarget;
2691
+ exports.pourPourable = pourPourable;
2692
+ exports.registerDispenseModels = registerDispenseModels;
2693
+ exports.replaceLine = replaceLine;
2694
+ exports.selectPourable = selectPourable;
2695
+ exports.sendIntent = sendIntent;
2696
+ exports.sendRfidOverride = sendRfidOverride;
2697
+ exports.unassignHolderIngredient = unassignHolderIngredient;
2698
+ //# sourceMappingURL=dispense-registration-manager-C6k10ipu.cjs.map