Repository URL to install this package:
|
Version:
1.1.3 ▾
|
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [0, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
var client_1 = require("./client");
var Picker = /** @class */ (function () {
function Picker(transport) {
this.client = new client_1.default(transport);
}
Picker.prototype.init = function (readMoreMode, priceMode, localisationId) {
if (readMoreMode === void 0) { readMoreMode = 'AVAILABILITY_FLAG'; }
if (priceMode === void 0) { priceMode = 'Loan'; }
if (localisationId === void 0) { localisationId = false; }
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.client.sessionInit('/**', readMoreMode)];
case 1:
_a.sent();
return [4 /*yield*/, this.client.sessionSetPriceMode(priceMode, 'Always', [])];
case 2:
_a.sent();
if (!localisationId) return [3 /*break*/, 4];
return [4 /*yield*/, this.client.sessionSetPriceLocalisation(localisationId)];
case 3:
_a.sent();
_a.label = 4;
case 4: return [4 /*yield*/, this.initSettings()];
case 5:
_a.sent();
return [2 /*return*/];
}
});
});
};
Picker.prototype.loadConfig = function (config) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
this.ensureSession();
return [4 /*yield*/, this.client.sessionLoadConfig(config)];
case 1:
_a.sent();
return [4 /*yield*/, this.initSettings()];
case 2:
_a.sent();
return [4 /*yield*/, this.initMenu()];
case 3:
_a.sent();
return [2 /*return*/];
}
});
});
};
Picker.prototype.toggleMenuItem = function (item) {
return __awaiter(this, void 0, void 0, function () {
var response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
this.ensureSession();
return [4 /*yield*/, this.client.sessionToggleItem(item)];
case 1:
response = _a.sent();
if (!response) return [3 /*break*/, 3];
return [4 /*yield*/, this.client.sessionApplySuggestion(response.result[0])];
case 2:
_a.sent();
_a.label = 3;
case 3: return [2 /*return*/];
}
});
});
};
Object.defineProperty(Picker.prototype, "vds", {
get: function () {
return this.client;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Picker.prototype, "models", {
get: function () {
this.ensureSession();
return this.introPage.groups.reduce(function (data, group) {
if (group.header === 'laddhybrid') {
return data;
}
return group.configs.reduce(function (data, config) {
data.push({
modelId: parseInt(config.linkConfig.data.substr(2, 3), 10),
name: config.title,
config: config.linkConfig
});
return data;
}, data);
}, []);
},
enumerable: true,
configurable: true
});
Object.defineProperty(Picker.prototype, "menuItems", {
get: function () {
return this.client.sessionGetStateUpdate().menuItems;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Picker.prototype, "menuTree", {
get: function () {
return this.client.sessionGetStateUpdate().menuTree;
},
enumerable: true,
configurable: true
});
Picker.prototype.extractMenuItemsByMenuId = function (menuId) {
return this.extractMenuItems(this.findMenuNodeById(menuId));
};
Picker.prototype.extractMenuItems = function (node) {
var _this = this;
return this.extractMenuItemIds(node)
.map(function (id) { return _this.findMenuItemById(id); })
.filter(function (item) { return item.visible; });
};
Picker.prototype.extractMenuItemIds = function (node) {
var items = [];
if (node.nodeType === 'ITEM') {
return [node.id];
}
if (node.children) {
for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
var child = _a[_i];
items = items.concat(this.extractMenuItemIds(child));
}
}
return items;
};
Picker.prototype.findMenuItemById = function (id) {
return this.menuItems.find(function (item) { return item.id === id; });
};
Picker.prototype.findMenuNodeById = function (id, node) {
if (!node) {
node = this.menuTree;
}
if (node.id === id) {
return node;
}
if (node.children) {
for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
var child = _a[_i];
var childNode = this.findMenuNodeById(id, child);
if (childNode) {
return childNode;
}
}
}
return null;
};
Picker.prototype.ensureSession = function () {
if (!this.introPage) {
throw new Error('Session must be initialised');
}
};
Picker.prototype.initSettings = function () {
return __awaiter(this, void 0, void 0, function () {
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = this;
return [4 /*yield*/, this.client.getIntroPage()];
case 1:
_a.introPage = _b.sent();
return [2 /*return*/];
}
});
});
};
Picker.prototype.initMenu = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.client.sessionToggleItem(this.client.sessionGetRootMenuItems()[0])];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
return Picker;
}());
exports.Picker = Picker;
exports.default = Picker;
//# sourceMappingURL=picker.js.map