@iotize/tap
Version:
IoTize Device client for Javascript
2,995 lines • 148 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@iotize/common/error'), require('@iotize/tap/service/impl/firmware'), require('@iotize/common/byte-converter'), require('@iotize/common/task-manager'), require('@iotize/common/utility'), require('@iotize/tap'), require('@iotize/tap/auth'), require('@iotize/tap/client/api'), require('@iotize/tap/client/impl'), require('@iotize/tap/data'), require('@iotize/tap/service/all'), require('@iotize/tap/service/impl/variable'), require('@iotize/tap/config/schema/v1'), require('ajv'), require('@iotize/tap/service/core'), require('@iotize/tap/service/impl/target')) :
typeof define === 'function' && define.amd ? define('@iotize/tap/configurator', ['exports', '@iotize/common/error', '@iotize/tap/service/impl/firmware', '@iotize/common/byte-converter', '@iotize/common/task-manager', '@iotize/common/utility', '@iotize/tap', '@iotize/tap/auth', '@iotize/tap/client/api', '@iotize/tap/client/impl', '@iotize/tap/data', '@iotize/tap/service/all', '@iotize/tap/service/impl/variable', '@iotize/tap/config/schema/v1', 'ajv', '@iotize/tap/service/core', '@iotize/tap/service/impl/target'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.iotize = global.iotize || {}, global.iotize.tap = global.iotize.tap || {}, global.iotize.tap.configurator = {}), global.error, global.iotize.tap.service.impl.firmware, global.byteConverter, global.taskManager, global.utility, global.iotize.tap, global.iotize.tap.auth, global.iotize.tap.client.api, global.iotize.tap.client.impl, global.iotize.tap.data, global.iotize.tap.service.all, global.iotize.tap.service.impl.variable, global.iotize.tap.config.schema.v1, global.Ajv, global.iotize.tap.service.core, global.iotize.tap.service.impl.target));
})(this, (function (exports, error, firmware, byteConverter, taskManager, utility, tap, auth, api, impl, data, all, variable, v1, Ajv, core, target) { 'use strict';
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var Ajv__default = /*#__PURE__*/_interopDefaultLegacy(Ajv);
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b)
if (Object.prototype.hasOwnProperty.call(b, p))
d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function () {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
r = Reflect.decorate(decorators, target, key, desc);
else
for (var i = decorators.length - 1; i >= 0; i--)
if (d = decorators[i])
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); };
}
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
return Reflect.metadata(metadataKey, metadataValue);
}
function __awaiter$2(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
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) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(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 = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
return t;
if (y = 0, t)
op = [op[0] & 2, 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 };
}
}
var __createBinding = Object.create ? (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
}) : (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
o[k2] = m[k];
});
function __exportStar(m, o) {
for (var p in m)
if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
__createBinding(o, m, p);
}
function __values(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m)
return m.call(o);
if (o && typeof o.length === "number")
return {
next: function () {
if (o && i >= o.length)
o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m)
return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
ar.push(r.value);
}
catch (error) {
e = { error: error };
}
finally {
try {
if (r && !r.done && (m = i["return"]))
m.call(i);
}
finally {
if (e)
throw e.error;
}
}
return ar;
}
/** @deprecated */
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
/** @deprecated */
function __spreadArrays() {
for (var s = 0, i = 0, il = arguments.length; i < il; i++)
s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
}
function __spreadArray(to, from, pack) {
if (pack || arguments.length === 2)
for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar)
ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
}
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator)
throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n])
i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try {
step(g[n](v));
}
catch (e) {
settle(q[0][3], e);
} }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length)
resume(q[0][0], q[0][1]); }
}
function __asyncDelegator(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
}
function __asyncValues(o) {
if (!Symbol.asyncIterator)
throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
}
function __makeTemplateObject(cooked, raw) {
if (Object.defineProperty) {
Object.defineProperty(cooked, "raw", { value: raw });
}
else {
cooked.raw = raw;
}
return cooked;
}
;
var __setModuleDefault = Object.create ? (function (o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function (o, v) {
o["default"] = v;
};
function __importStar(mod) {
if (mod && mod.__esModule)
return mod;
var result = {};
if (mod != null)
for (var k in mod)
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
__createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
}
function __importDefault(mod) {
return (mod && mod.__esModule) ? mod : { default: mod };
}
function __classPrivateFieldGet(receiver, state, kind, f) {
if (kind === "a" && !f)
throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
}
function __classPrivateFieldSet(receiver, state, value, kind, f) {
if (kind === "m")
throw new TypeError("Private method is not writable");
if (kind === "a" && !f)
throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
}
/**
* TODO move to TapConfiguratorError
*/
var ConfigKeyNotSupportedByFirmwareVersion = /** @class */ (function (_super) {
__extends(ConfigKeyNotSupportedByFirmwareVersion, _super);
function ConfigKeyNotSupportedByFirmwareVersion(configKey, firmwareVersion, constraint) {
var _this = _super.call(this, "Configuration key \"" + configKey + "\" is not available for you firmware version (" + firmwareVersion + "). " + (constraint.minApiVersion
? "Minimal firmware version: " + constraint.minApiVersion + "."
: '') + (constraint.maxApiVersion
? "Maximal firmware version: " + constraint.maxApiVersion + "."
: '')) || this;
_this.configKey = configKey;
_this.firmwareVersion = firmwareVersion;
_this.constraint = constraint;
return _this;
}
return ConfigKeyNotSupportedByFirmwareVersion;
}(Error));
exports.TapConfiguratorError = /** @class */ (function (_super) {
__extends(TapConfiguratorError, _super);
function TapConfiguratorError(code, msg, cause) {
var _this = _super.call(this, msg, code) || this;
_this.cause = cause;
return _this;
}
TapConfiguratorError.internalError = function (msg, cause) {
return new TapConfiguratorError(TapConfiguratorError.Code.InternalError, msg, cause);
};
TapConfiguratorError.unexpectedFirmwareState = function (state) {
return new TapConfiguratorError(TapConfiguratorError.Code.UnexpectedFirmwareState, "Firmware state is not in expected mode. It should be " + firmware.FirmwareState.NORMAL + " or " + firmware.FirmwareState.LEGACY + " but found " + state);
};
TapConfiguratorError.invalidConfiguration = function (message) {
return new TapConfiguratorError(TapConfiguratorError.Code.InvalidSchema, message);
};
return TapConfiguratorError;
}(error.CodeError));
(function (TapConfiguratorError) {
var Code;
(function (Code) {
Code["UnexpectedFirmwareState"] = "TapConfiguratorErrorUnexpectedFirmwareState";
Code["InvalidSchema"] = "TapConfiguratorErrorIvalidSchema";
Code["InternalError"] = "TapConfiguratorErrorInternalError";
})(Code = TapConfiguratorError.Code || (TapConfiguratorError.Code = {}));
var InvalidSchemaError = /** @class */ (function (_super) {
__extends(InvalidSchemaError, _super);
function InvalidSchemaError(validate) {
var _this = _super.call(this, Code.InvalidSchema, "Invalid Tap configuration file:\n" + InvalidSchemaError.ajvErrorsToString(validate.errors)) || this;
_this.validate = validate;
_this.errors = _this.validate.errors || [];
return _this;
}
InvalidSchemaError.ajvErrorsToString = function (errors) {
// console.log('errors', JSON.stringify(errors, undefined, 4));
return errors
? errors
.map(function (error) {
var message;
var instancePath = error.instancePath || error.dataPath;
switch (error.keyword) {
case 'additionalProperties':
var params = error.params;
message = instancePath + " should not have additional property \"" + params
.additionalProperty + "\"";
break;
default:
message = instancePath + " " + error.message + " (keyword: " + error.keyword + ")";
}
return "\t- " + message;
})
.join('\n')
: 'Unknown errors';
};
return InvalidSchemaError;
}(TapConfiguratorError));
TapConfiguratorError.InvalidSchemaError = InvalidSchemaError;
})(exports.TapConfiguratorError || (exports.TapConfiguratorError = {}));
var ANONYMOUS_USER = {
username: 'anonymous',
password: '',
id: 0,
lifeTime: 30,
};
var ADMIN_USER = {
username: 'admin',
password: 'admin',
id: 0xffff,
lifeTime: 30,
};
var SUPERVISOR_USER = {
username: 'supervisor',
password: 'supervisor',
id: 0xfffe,
lifeTime: 30,
};
var SERIAL_SERVER_USER = {
username: 'SerialServer',
password: 'SerialServer',
lifeTime: 4000,
id: 0xfffc,
};
var SPECIAL_USERS = [
ANONYMOUS_USER,
ADMIN_USER,
SUPERVISOR_USER,
];
var DEFAULT_HASH_ITERATION_COUNT = 5000;
function getProfileIdFromConfig(profile) {
var specialUserInfo = SPECIAL_USERS.find(function (v) { return profile.username === v.username; });
if (specialUserInfo) {
return specialUserInfo.id;
}
var profileId = profile['id']; // TODO check
if (profileId === undefined) {
throw exports.TapConfiguratorError.invalidConfiguration("Profile id is required for " + profile['username']);
}
return profileId;
}
/**
*
* @param versionToCheck
* @param versionToCompareTo
* @returns
* 1 if versionToCheck > versionToCompareTo
* 0 if versionToCheck == versionToCompareTo
* -1 if versionToCheck < versionToCompareTo
*/
function compareVersionNumbers(versionToCheck, versionToCompareTo) {
var v1parts = versionToCheck.split('.').map(function (v) {
var asInt = parseInt(v);
if (isNaN(asInt)) {
throw new Error("Value \"" + versionToCheck + "\" is not a valid string version");
}
return asInt;
});
var v2parts = versionToCompareTo.split('.').map(function (v) {
var asInt = parseInt(v);
if (isNaN(asInt)) {
throw new Error("Value \"" + versionToCompareTo + "\" is not a valid string version");
}
return asInt;
});
for (var i = 0; i < v1parts.length; ++i) {
if (v2parts.length === i) {
return 1;
}
if (v1parts[i] === v2parts[i]) {
continue;
}
if (v1parts[i] > v2parts[i]) {
return 1;
}
return -1;
}
if (v1parts.length != v2parts.length) {
return -1;
}
return 0;
}
/**
* Return true if versionToCheck >= versionToCompareTo
* @param versionToCheck version to check
* @param versionToCompareTo version to compare to
* @returns versionToCheck >= versionToCompareTo
*/
function isTapFirmwareVersionGreaterThanOrEqual(versionToCheck, versionToCompareTo) {
return compareVersionNumbers(versionToCheck, versionToCompareTo) >= 0;
}
/**
* Return true if versionToCheck <= versionToCompareTo
* @param versionToCheck
* @param versionToCompareTo
* @returns versionToCheck <= versionToCompareTo
*/
function isTapFirmwareVersionLessThanOrEqual(versionToCheck, versionToCompareTo) {
return compareVersionNumbers(versionToCheck, versionToCompareTo) <= 0;
}
function enumKeyToEnumValue(value, enumMapping) {
return toEnum(value, enumMapping);
}
function enumKeysToEnumValues(values, enumMapping) {
return values.map(function (value) { return enumKeyToEnumValue(value, enumMapping); });
}
/**
* Convert
*/
function toEnum(value, enumMapping) {
if (!value) {
throw new Error("Missing first attribute for toEnum. " + Object.keys(enumMapping).join(', '));
}
if (typeof value !== 'string') {
throw new Error("Enum key must be a string. Given: " + JSON.stringify(value) + ". " + Object.keys(enumMapping).join(', '));
}
value = value.toUpperCase();
if (!(value in enumMapping)) {
throw new Error("Missing enum value \"" + value + "\". Available: " + Object.keys(enumMapping).join(', '));
}
return enumMapping[value];
}
function enumToString(value, mapping) {
if (!(value in mapping)) {
throw new Error("Missing mapping for " + value + ". Available: " + Object.keys(mapping).join(', '));
}
return mapping[value];
}
function isSpecialProfileUsername(username) {
return SPECIAL_USERS.filter(function (v) { return username === v.username; }).length > 0;
}
function isSpecialProfileId(id) {
return SPECIAL_USERS.filter(function (v) { return id === v.id; }).length > 0;
}
function configValueToBytes(input) {
if (input instanceof Uint8Array) {
return input;
}
else if (typeof input === 'string') {
if (input.substring(0, 2).toLowerCase() === '0x') {
return byteConverter.hexStringToBuffer(input);
}
else {
return byteConverter.asciiStringToByteBuffer(input);
}
}
else {
return Uint8Array.from(input);
}
}
function getByAttr(filterKey, v, data) {
var array;
if (Array.isArray(data)) {
array = data;
}
else {
array = Object.keys(data).map(function (key) { return data[key]; });
}
return array.filter(function (value) { return value[filterKey] == v; })[0] || undefined;
}
var TSTYPE_CLASS = {
Uint8Array: Uint8Array,
};
var ɵ0$4 = function (schema) {
var classObject = TSTYPE_CLASS[schema];
return function (data) {
return !classObject || data instanceof classObject;
};
};
var tsTypeKeyword = {
keyword: 'tsType',
compile: ɵ0$4,
};
var ipv4Format = /^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/;
function createAjvInstance(schemas) {
schemas = schemas || [
v1.TapConfigJsonSchema,
v1.CommonTypeJsonSchema,
v1.TapTypeJsonSchema,
];
var ajv8Options = {
schemas: schemas,
strict: false,
strictSchema: false,
};
var ajv = new Ajv__default["default"](ajv8Options);
ajv.addKeyword(tsTypeKeyword.keyword, tsTypeKeyword);
ajv.addFormat('ipv4', ipv4Format);
return ajv;
}
function getJsonSchemaValidator(schemas) {
var ajv = createAjvInstance();
var schemaId = 'http://iotize.com/schemas/v1/tap-config.json'; // TODO config must match schema api file value
var validator = ajv.getSchema(schemaId);
if (!validator) {
throw new Error("Cannot create JSON validator function from schema " + schemaId);
}
return validator;
}
// export function checkErrors(config: Object) {
// const validator = getJsonSchemaValidator();
// validator(config);
// return validator.errors;
// }
/**
* Validate schema. Throw error if schema is not valid
* @throws @{link TapConfiguratorError}
* @param config the tap config object
* @param schemas optial schema used for validation. If not provided, default one will be used
*
* @returns validator function
*/
function validateTapConfiguratorConfig(config, schemas) {
var validator = getJsonSchemaValidator(schemas);
var valid = validator(config);
if (!valid) {
throw new exports.TapConfiguratorError.InvalidSchemaError(validator);
}
return validator;
}
function parseTapConfiguratorConfig(input) {
var config;
try {
config = JSON.parse(input);
}
catch (err) {
throw new Error("Cannot parse Tap configurator config content. " + err.message);
}
validateTapConfiguratorConfig(config);
return config;
}
/**
* Generated file. Do not edit
*/
var ɵ0$3 = function (context) {
return context.service.interface.putApplicationDataCall(configValueToBytes(context.value));
}, ɵ1$2 = function (context) {
return context.service.interface.putAppNameCall(context.value);
}, ɵ2$2 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.113')) {
return new ConfigKeyNotSupportedByFirmwareVersion('application.productCode', context.firmwareVersion, {
minApiVersion: '1.113',
maxApiVersion: undefined,
});
}
}
return context.service.interface.putProductCodeCall(context.value);
}, ɵ3$1 = function (context) {
return context.service.interface.putUniversalLinkCall(context.value);
}, ɵ4$1 = function (context) {
return context.service.interface.putAppPathCall(context.value);
}, ɵ5$1 = function (context) {
return context.service.cloud.putDataLogPublishTopicCall(context.value);
}, ɵ6$1 = function (context) {
return context.service.cloud.putDataLogSubscribeTopicCall(context.value);
}, ɵ7$1 = function (context) {
return context.service.cloud.putDataLogUploadPeriodCall(context.value);
}, ɵ8$1 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionLessThanOrEqual(context.firmwareVersion, '1.103')) {
return new ConfigKeyNotSupportedByFirmwareVersion('cloud.mqtt.brokerPort', context.firmwareVersion, {
minApiVersion: undefined,
maxApiVersion: '1.103',
});
}
}
return context.service.cloud.putMqttBrokerPortCall(context.value);
}, ɵ9$1 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionLessThanOrEqual(context.firmwareVersion, '1.103')) {
return new ConfigKeyNotSupportedByFirmwareVersion('cloud.mqtt.clientId', context.firmwareVersion, {
minApiVersion: undefined,
maxApiVersion: '1.103',
});
}
}
return context.service.cloud.putMqttClientIdCall(context.value);
}, ɵ10$1 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionLessThanOrEqual(context.firmwareVersion, '1.103')) {
return new ConfigKeyNotSupportedByFirmwareVersion('cloud.mqtt.password', context.firmwareVersion, {
minApiVersion: undefined,
maxApiVersion: '1.103',
});
}
}
return context.service.cloud.putMqttPasswordCall(context.value);
}, ɵ11$1 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionLessThanOrEqual(context.firmwareVersion, '1.103')) {
return new ConfigKeyNotSupportedByFirmwareVersion('cloud.mqtt.username', context.firmwareVersion, {
minApiVersion: undefined,
maxApiVersion: '1.103',
});
}
}
return context.service.cloud.putMqttUsernameCall(context.value);
}, ɵ12$1 = function (context) {
return context.service.cloud.putPlatformCall(enumKeyToEnumValue(context.value, all.CloudPlatform));
}, ɵ13$1 = function (context) {
return context.service.interface.putConfigFormatVersionCall(context.value);
}, ɵ14$1 = function (context) {
return context.service.bundle.createCall(context.param);
}, ɵ15$1 = function (context) {
return context.service.bundle.putAclCall(context.param, context.value);
}, ɵ16$1 = function (context) {
return context.service.bundle.putDataLogCryptoGroupIdCall(context.param, context.value);
}, ɵ17$1 = function (context) {
return context.service.bundle.putDataLogPeriodCall(context.param, context.value);
}, ɵ18$1 = function (context) {
return context.service.bundle.putNameCall(context.param, context.value);
}, ɵ19$1 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.23')) {
return new ConfigKeyNotSupportedByFirmwareVersion('data.features[].bundleId', context.firmwareVersion, {
minApiVersion: '1.23',
maxApiVersion: undefined,
});
}
}
return context.service.interface.setSpecialFeatureProfileCall(context.param, context.value);
}, ɵ20$1 = function (context) {
return context.service.group.createCall(context.param);
}, ɵ21$1 = function (context) {
return context.service.group.putAliasCall(context.param, context.value);
}, ɵ22$1 = function (context) {
return context.service.group.changePasswordKeyCall(context.param, configValueToBytes(context.value));
}, ɵ23$1 = function (context) {
return context.service.group.putSessionLifetimeCall(context.param, context.value);
}, ɵ24$1 = function (context) {
return context.service.group.changePasswordCall(context.param, context.value);
}, ɵ25$1 = function (context) {
return context.service.group.putNameCall(context.param, context.value);
}, ɵ26$1 = function (context) {
return context.service.variable.createCall(context.param, context.value);
}, ɵ27$1 = function (context) {
return context.service.variable.putVariableAddressCall(context.param, context.value);
}, ɵ28$1 = function (context) {
return context.service.variable.putBundleIdCall(context.param, context.value);
}, ɵ29$1 = function (context) {
return context.service.variable.putNumberOfElementsCall(context.param, context.value);
}, ɵ30$1 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.73')) {
return new ConfigKeyNotSupportedByFirmwareVersion('data.variables[].meta', context.firmwareVersion, {
minApiVersion: '1.73',
maxApiVersion: undefined,
});
}
}
return context.service.variable.putMetaCall(context.param, context.value);
}, ɵ31$1 = function (context) {
return context.service.variable.putModbusVariableAddressCall(context.param, context.value);
}, ɵ32$1 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.73')) {
return new ConfigKeyNotSupportedByFirmwareVersion('data.variables[].rawMeta', context.firmwareVersion, {
minApiVersion: '1.73',
maxApiVersion: undefined,
});
}
}
return context.service.variable.putRawMetaCall(context.param, configValueToBytes(context.value));
}, ɵ33$1 = function (context) {
return context.service.variable.putTypeCall(context.param, context.value);
}, ɵ34$1 = function (context) {
return context.service.variable.setValueCall(context.param, configValueToBytes(context.value));
}, ɵ35$1 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.90')) {
return new ConfigKeyNotSupportedByFirmwareVersion('jvm.code', context.firmwareVersion, {
minApiVersion: '1.90',
maxApiVersion: undefined,
});
}
}
return context.service.jvm.appendCodeAppendCalls(configValueToBytes(context.value));
}, ɵ36$1 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.90')) {
return new ConfigKeyNotSupportedByFirmwareVersion('jvm.codeSize', context.firmwareVersion, {
minApiVersion: '1.90',
maxApiVersion: undefined,
});
}
}
return context.service.jvm.putCodeSizeCall(context.value);
}, ɵ37$1 = function (context) {
return context.service.jvm.putProfileIdCall(context.value);
}, ɵ38$1 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '2.7')) {
return new ConfigKeyNotSupportedByFirmwareVersion('ports.ethernet.gatewayIp', context.firmwareVersion, {
minApiVersion: '2.7',
maxApiVersion: undefined,
});
}
}
return context.service.ethernet.putGatewayIpCall(context.value);
}, ɵ39$1 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '2.7')) {
return new ConfigKeyNotSupportedByFirmwareVersion('ports.ethernet.ip', context.firmwareVersion, {
minApiVersion: '2.7',
maxApiVersion: undefined,
});
}
}
return context.service.ethernet.putIpCall(context.value);
}, ɵ40$1 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '2.7')) {
return new ConfigKeyNotSupportedByFirmwareVersion('ports.ethernet.ipMask', context.firmwareVersion, {
minApiVersion: '2.7',
maxApiVersion: undefined,
});
}
}
return context.service.ethernet.putIpMaskCall(context.value);
}, ɵ41$1 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '2.11')) {
return new ConfigKeyNotSupportedByFirmwareVersion('tap.autoRebootTimeout', context.firmwareVersion, {
minApiVersion: '2.11',
maxApiVersion: undefined,
});
}
}
return context.service.interface.putAutoRebootTimeoutCall(context.value);
}, ɵ42$1 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.86')) {
return new ConfigKeyNotSupportedByFirmwareVersion('tap.certificate.privateKey', context.firmwareVersion, {
minApiVersion: '1.86',
maxApiVersion: undefined,
});
}
}
return context.service.interface.putCertificatePrivateKeyAppendCalls(configValueToBytes(context.value));
}, ɵ43$1 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.86')) {
return new ConfigKeyNotSupportedByFirmwareVersion('tap.certificate.publicKey', context.firmwareVersion, {
minApiVersion: '1.86',
maxApiVersion: undefined,
});
}
}
return context.service.interface.putCertificatePublicKeyAppendCalls(configValueToBytes(context.value));
}, ɵ44$1 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.86')) {
return new ConfigKeyNotSupportedByFirmwareVersion('tap.certificate.rootKey', context.firmwareVersion, {
minApiVersion: '1.86',
maxApiVersion: undefined,
});
}
}
return context.service.interface.putCertificateRootKeyAppendCalls(configValueToBytes(context.value));
}, ɵ45$1 = function (context) {
return context.service.interface.putMaxLowPowerTimeCall(context.value);
}, ɵ46$1 = function (context) {
return context.service.interface.putPowerOptimisationLevelCall(enumKeyToEnumValue(context.value, all.LowPowerOptimizationLevel));
}, ɵ47$1 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '2.15')) {
return new ConfigKeyNotSupportedByFirmwareVersion('tap.powerOptimizationOptions', context.firmwareVersion, {
minApiVersion: '2.15',
maxApiVersion: undefined,
});
}
}
return context.service.interface.putPowerOptimisationOptionsCall(context.value);
}, ɵ48$1 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.11')) {
return new ConfigKeyNotSupportedByFirmwareVersion('tap.scram.hashIteration', context.firmwareVersion, {
minApiVersion: '1.11',
maxApiVersion: undefined,
});
}
}
return context.service.scram.putHashIterationCall(context.value);
}, ɵ49$1 = function (context) {
return context.service.interface.putSecurityOptionsCall(context.value);
}, ɵ50$1 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.107')) {
return new ConfigKeyNotSupportedByFirmwareVersion('tap.time.ntpServer', context.firmwareVersion, {
minApiVersion: '1.107',
maxApiVersion: undefined,
});
}
}
return context.service.time.putNtpServerCall(context.value);
}, ɵ51$1 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.107')) {
return new ConfigKeyNotSupportedByFirmwareVersion('tap.time.zone', context.firmwareVersion, {
minApiVersion: '1.107',
maxApiVersion: undefined,
});
}
}
return context.service.time.putTimeZoneCall(context.value);
}, ɵ52$1 = function (context) {
return context.service.target.putFirmwareVersionCall(context.value);
}, ɵ53$1 = function (context) {
return context.service.target.putModbusDefaultSlaveAddressCall(context.value);
}, ɵ54$1 = function (context) {
return context.service.target.putProtocolCall(enumKeyToEnumValue(context.value, all.TargetProtocol));
}, ɵ55$1 = function (context) {
return context.service.interface.putConfigVersionCall(context.value);
}, ɵ56$1 = function (context) {
return context.service.interface.putAuthorizedHostProtocolCall(enumKeysToEnumValues(context.value, all.HostProtocol));
}, ɵ57$1 = function (context) {
return context.service.interface.putHostInactivityPeriodCall(context.value);
}, ɵ58$1 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '2.13')) {
return new ConfigKeyNotSupportedByFirmwareVersion('wireless.options.network', context.firmwareVersion, {
minApiVersion: '2.13',
maxApiVersion: undefined,
});
}
}
return context.service.interface.putNetworkOptionsCall(context.value);
}, ɵ59$1 = function (context) {
return context.service.interface.putPairingOptionsCall(context.value);
}, ɵ60$1 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '2.7')) {
return new ConfigKeyNotSupportedByFirmwareVersion('wireless.protocols.ethernet.dnsIp', context.firmwareVersion, {
minApiVersion: '2.7',
maxApiVersion: undefined,
});
}
}
return context.service.ethernet.putDnsIpCall(context.value);
}, ɵ61$1 = function (context) {
return context.service.lora.putConfigCall(context.value);
}, ɵ62$1 = function (context) {
return context.service.lora.putIdsCall(configValueToBytes(context.value));
}, ɵ63$1 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '2.11')) {
return new ConfigKeyNotSupportedByFirmwareVersion('wireless.protocols.lte.applicationData', context.firmwareVersion, {
minApiVersion: '2.11',
maxApiVersion: undefined,
});
}
}
return context.service.lte.putApplicationDataCall(configValueToBytes(context.value));
}, ɵ64$1 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.86')) {
return new ConfigKeyNotSupportedByFirmwareVersion('wireless.protocols.mqtt.brokerCertificate', context.firmwareVersion, {
minApiVersion: '1.86',
maxApiVersion: undefined,
});
}
}
return context.service.mqtt.putBrokerCertificateAppendCalls(configValueToBytes(context.value));
}, ɵ65$1 = function (context) {
return context.service.mqtt.putBrokerHostnameCall(context.value);
}, ɵ66$1 = function (context) {
return context.service.mqtt.putBrokerPortCall(context.value);
}, ɵ67$1 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.86')) {
return new ConfigKeyNotSupportedByFirmwareVersion('wireless.protocols.mqtt.clientId', context.firmwareVersion, {
minApiVersion: '1.86',
maxApiVersion: undefined,
});
}
}
return context.service.mqtt.putClientIdCall(context.value);
}, ɵ68$1 = function (context) {
return context.service.mqtt.putPasswordCall(context.value);
}, ɵ69$1 = function (context) {
return context.service.mqtt.putRelayNetKeyCall(context.value);
}, ɵ70$1 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.86')) {
return new ConfigKeyNotSupportedByFirmwareVersion('wireless.protocols.mqtt.requestTopic', context.firmwareVersion, {
minApiVersion: '1.86',
maxApiVersion: undefined,
});
}
}
return context.service.mqtt.putRequestTopicCall(context.value);
}, ɵ71$1 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.107')) {
return new ConfigKeyNotSupportedByFirmwareVersion('wireless.protocols.mqtt.responseTopic', context.firmwareVersion, {
minApiVersion: '1.107',
maxApiVersion: undefined,
});
}
}
return context.service.mqtt.putResponseTopicCall(context.value);
}, ɵ72$1 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.86')) {
return new ConfigKeyNotSupportedByFirmwareVersion('wireless.protocols.mqtt.topicPrefix', context.firmwareVersion, {
minApiVersion: '1.86',
maxApiVersion: undefined,
});
}
}
return context.service.mqtt.putTopicPrefixCall(context.value);
}, ɵ73$1 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.86')) {
return new ConfigKeyNotSupportedByFirmwareVersion('wireless.protocols.mqtt.username', context.firmwareVersion, {
minApiVersion: '1.86',
maxApiVersion: undefined,
});
}
}
return context.service.mqtt.putUsernameCall(context.value);
}, ɵ74 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.55')) {
return new ConfigKeyNotSupportedByFirmwareVersion('wireless.protocols.nfc.autoLogProfileId', context.firmwareVersion, {
minApiVersion: '1.55',
maxApiVersion: undefined,
});
}
}
return context.service.interface.putNfcAutologProfileIdCall(context.value);
}, ɵ75 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.85')) {
return new ConfigKeyNotSupportedByFirmwareVersion('wireless.protocols.nfc.connectionPriority', context.firmwareVersion, {
minApiVersion: '1.85',
maxApiVersion: undefined,
});
}
}
return context.service.interface.putNfcConnectionPriorityCall(enumKeyToEnumValue(context.value, all.NfcConnectionPriority));
}, ɵ76 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.88')) {
return new ConfigKeyNotSupportedByFirmwareVersion('wireless.protocols.wifi.countryCode', context.firmwareVersion, {
minApiVersion: '1.88',
maxApiVersion: undefined,
});
}
}
return context.service.wifi.putCountryCodeCall(context.value);
}, ɵ77 = function (context) {
return context.service.wifi.putDnsIpCall(context.value);
}, ɵ78 = function (context) {
return context.service.wifi.putGatewayIpCall(context.value);
}, ɵ79 = function (context) {
return context.service.wifi.putIpCall(context.value);
}, ɵ80 = function (context) {
return context.service.wifi.putKeyCall(context.value);
}, ɵ81 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.88')) {
return new ConfigKeyNotSupportedByFirmwareVersion('wireless.protocols.wifi.keyVisibility', context.firmwareVersion, {
minApiVersion: '1.88',
maxApiVersion: undefined,
});
}
}
return context.service.wifi.putKeyVisibilityCall(enumKeyToEnumValue(context.value, all.WifiKeyVisibility));
}, ɵ82 = function (context) {
return context.service.wifi.putIpMaskCall(context.value);
}, ɵ83 = function (context) {
return context.service.wifi.putModeCall(enumKeyToEnumValue(context.value, all.WifiMode));
}, ɵ84 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '2.13')) {
return new ConfigKeyNotSupportedByFirmwareVersion('wireless.protocols.wifi.networkMode', context.firmwareVersion, {
minApiVersion: '2.13',
maxApiVersion: undefined,
});
}
}
return context.service.wifi.putNetworkModeCall(enumKeyToEnumValue(context.value, all.WifiMode));
}, ɵ85 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.88')) {
return new ConfigKeyNotSupportedByFirmwareVersion('wireless.protocols.wifi.protocol', context.firmwareVersion, {
minApiVersion: '1.88',
maxApiVersion: undefined,
});
}
}
return context.service.wifi.putProtocolCall(enumKeysToEnumValues(context.value, all.WifiProtocol));
}, ɵ86 = function (context) {
return context.service.wifi.putSSIDCall(context.value);
}, ɵ87 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.88')) {
return new ConfigKeyNotSupportedByFirmwareVersion('wireless.protocols.wifi.ssidVisibility', context.firmwareVersion, {
minApiVersion: '1.88',
maxApiVersion: undefined,
});
}
}
return context.service.wifi.putSSIDVisibilityCall(enumKeyToEnumValue(context.value, all.WifiSSIDVisibility));
}, ɵ88 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.88')) {
return new ConfigKeyNotSupportedByFirmwareVersion('wireless.protocols.wifi.txPower', context.firmwareVersion, {
minApiVersion: '1.88',
maxApiVersion: undefined,
});
}
}
return context.service.wifi.putTxPowerCall(context.value);
};
var WRITE_CONFIGURATOR_CONFIG$1 = {
'application.data': ɵ0$3,
'application.name': ɵ1$2,
'application.productCode': ɵ2$2,
'application.universalLink': ɵ3$1,
'application.uri': ɵ4$1,
'cloud.dataLog.mqttPublishTopic': ɵ5$1,
'cloud.dataLog.mqttSubscribeTopic': ɵ6$1,
'cloud.dataLog.uploadPeriod': ɵ7$1,
'cloud.mqtt.brokerPort': ɵ8$1,
'cloud.mqtt.clientId': ɵ9$1,
'cloud.mqtt.password': ɵ10$1,
'cloud.mqtt.username': ɵ11$1,
'cloud.platform': ɵ12$1,
configFormatVersion: ɵ13$1,
'data.bundles[]': ɵ14$1,
'data.bundles[].acl[].$': ɵ15$1,
'data.bundles[].dataLog.cryptoGroupId': ɵ16$1,
'data.bundles[].dataLog.period': ɵ17$1,
'data.bundles[].name': ɵ18$1,
'data.features[].bundleId': ɵ19$1,
'data.profiles[]': ɵ20$1,
'data.profiles[].alias': ɵ21$1,
'data.profiles[].key': ɵ22$1,
'data.profiles[].lifeTime': ɵ23$1,
'data.profiles[].password': ɵ24$1,
'data.profiles[].username': ɵ25$1,
'data.variables[]': ɵ26$1,
'data.variables[].address': ɵ27$1,
'data.variables[].bundleId': ɵ28$1,
'data.variables[].length': ɵ29$1,
'data.variables[].meta': ɵ30$1,
'data.variables[].modbusAddress': ɵ31$1,
'data.variables[].rawMeta': ɵ32$1,
'data.variables[].type': ɵ33$1,
'data.variables[].value': ɵ34$1,
'jvm.code': ɵ35$1,
'jvm.codeSize': ɵ36$1,
'jvm.profileId': ɵ37$1,
'ports.ethernet.gatewayIp': ɵ38$1,
'ports.ethernet.ip': ɵ39$1,
'ports.ethernet.ipMask': ɵ40$1,
'tap.autoRebootTimeout': ɵ41$1,
'tap.certificate.privateKey': ɵ42$1,
'tap.certificate.publicKey': ɵ43$1,
'tap.certificate.rootKey': ɵ44$1,
'tap.maxLowPowerTime': ɵ45$1,
'tap.powerOptimization': ɵ46$1,
'tap.powerOptimizationOptions': ɵ47$1,
'tap.scram.hashIteration': ɵ48$1,
'tap.security': ɵ49$1,
'tap.time.ntpServer': ɵ50$1,
'tap.time.zone': ɵ51$1,
'target.firmwareVersion': ɵ52$1,
'target.modbusDefaultSlaveAddress': ɵ53$1,
'target.protocol.type': ɵ54$1,
version: ɵ55$1,
'wireless.options.authorizedProtocols': ɵ56$1,
'wireless.options.inactivityTimeout': ɵ57$1,
'wireless.options.network': ɵ58$1,
'wireless.options.pairing': ɵ59$1,
'wireless.protocols.ethernet.dnsIp': ɵ60$1,
'wireless.protocols.lora.config': ɵ61$1,
'wireless.protocols.lora.ids': ɵ62$1,
'wireless.protocols.lte.applicationData': ɵ63$1,
'wireless.protocols.mqtt.brokerCertificate': ɵ64$1,
'wireless.protocols.mqtt.brokerHostname': ɵ65$1,
'wireless.protocols.mqtt.brokerPort': ɵ66$1,
'wireless.protocols.mqtt.clientId': ɵ67$1,
'wireless.protocols.mqtt.password': ɵ68$1,
'wireless.protocols.mqtt.relayNetKey': ɵ69$1,
'wireless.protocols.mqtt.requestTopic': ɵ70$1,
'wireless.protocols.mqtt.responseTopic': ɵ71$1,
'wireless.protocols.mqtt.topicPrefix': ɵ72$1,
'wireless.protocols.mqtt.username': ɵ73$1,
'wireless.protocols.nfc.autoLogProfileId': ɵ74,
'wireless.protocols.nfc.connectionPriority': ɵ75,
'wireless.protocols.wifi.countryCode': ɵ76,
'wireless.protocols.wifi.dnsIp': ɵ77,
'wireless.protocols.wifi.gatewayIp': ɵ78,
'wireless.protocols.wifi.ip': ɵ79,
'wireless.protocols.wifi.key': ɵ80,
'wireless.protocols.wifi.keyVisibility': ɵ81,
'wireless.protocols.wifi.mask': ɵ82,
'wireless.protocols.wifi.mode': ɵ83,
'wireless.protocols.wifi.networkMode': ɵ84,
'wireless.protocols.wifi.protocol': ɵ85,
'wireless.protocols.wifi.ssid': ɵ86,
'wireless.protocols.wifi.ssidVisibility': ɵ87,
'wireless.protocols.wifi.txPower': ɵ88,
};
var ɵ0$2 = function (context) {
var _a, _b, _c, _d, _e;
var protocolType = ((_b = (_a = context.config) === null || _a === void 0 ? void 0 : _a.target) === null || _b === void 0 ? void 0 : _b.type) === 'MCU'
? (_e = (_d = (_c = context.config) === null || _c === void 0 ? void 0 : _c.target) === null || _d === void 0 ? void 0 : _d.protocol) === null || _e === void 0 ? void 0 : _e.type
: 'MODBUS';
switch (protocolType) {
case 'NONE':
case 'SWD':
// case 'JTAG':
case 'GPIO':
case 'CUSTOM':
return exports.TapConfiguratorError.invalidConfiguration("Target protocol \"" + protocolType + "\" does not accept any additional configuration");
case 'S3P':
return context.service.target.putS3PConfigurationCall(context.value);
case 'MODBUS_TCP':
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '2.6')) {
return new ConfigKeyNotSupportedByFirmwareVersion('target.protocol.config', context.firmwareVersion, {
minApiVersion: '2.6',
maxApiVersion: undefined,
});
}
}
return context.service.target.putModbusTcpConfigurationCall(context.value);
case 'MODBUS':
case 'SERIAL':
var tapnpassConfigJson = context.value;
var tapnpassConfigApi = tapnpassConfigJsonToApi(tapnpassConfigJson);
return context.service.target.putSerialModbusConfigurationCall(tapnpassConfigApi);
case 'CAN':
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '2.6')) {
return new ConfigKeyNotSupportedByFirmwareVersion('target.protocol.config', context.firmwareVersion, {
minApiVersion: '2.6',
maxApiVersion: undefined,
});
}
}
var canConfigJson = context.value;
var canConfigApi = canConfigJsonToApi(canConfigJson);
return context.service.target.putCanConfigurationCall(canConfigApi);
default:
return exports.TapConfiguratorError.invalidConfiguration("Target protocol \"" + protocolType + "\" is not supported by this version of the configurator");
}
}, ɵ1$1 = function (context) {
var _a;
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '2.6')) {
return new ConfigKeyNotSupportedByFirmwareVersion('slaveServer', context.firmwareVersion, {
minApiVersion: '2.6',
maxApiVersion: undefined,
});
}
}
var protocolType = (_a = context.value) === null || _a === void 0 ? void 0 : _a.type;
switch (protocolType) {
case undefined:
throw new Error("Undefined property");
case 'SPI':
return context.service.slaveServer.putSpiProtocolConfigurationCall();
case 'MODBUS_TCP':
var modbusTcpConfig = context.value
.config;
return context.service.slaveServer.putModbusTcpProtocolConfigurationCall(modbusTcpConfig);
case 'MODBUS_RTU':
var tapnpassConfigJson = context.value
.config;
var tapnpassConfigApi = tapnpassConfigJsonToApi(tapnpassConfigJson);
return context.service.slaveServer.putModbusRtuProtocolConfigurationCall(tapnpassConfigApi);
case 'CAN':
var canConfigJson = context.value.config;
var canConfigApi = canConfigJsonToApi(canConfigJson);
return context.service.slaveServer.putCanProtocolConfigurationCall(canConfigApi);
default:
return exports.TapConfiguratorError.invalidConfiguration("Slave server protocol \"" + protocolType + "\" is not supported by this version of the configurator");
}
}, ɵ2$1 = function (context) {
var loadJvmCodeCalls = WRITE_CONFIGURATOR_CONFIG$1['jvm.code'](context);
if (loadJvmCodeCalls instanceof Error) {
return loadJvmCodeCalls;
}
else {
var clearCodeCall = context.service.jvm.clearCodeCall();
clearCodeCall.body = Uint8Array.from([0]);
return __spreadArray([clearCodeCall], __read(loadJvmCodeCalls));
}
};
var WRITE_CONFIGURATOR_CUSTOM_CONFIG = {
'target.protocol.config': ɵ0$2,
slaveServer: ɵ1$1,
'jvm.code': ɵ2$1,
};
var WRITE_CONFIGURATOR_CONFIG = Object.assign(Object.assign({}, WRITE_CONFIGURATOR_CONFIG$1), WRITE_CONFIGURATOR_CUSTOM_CONFIG);
var DEFAULT_MODBUS_CONFIG = {
offsetFirstRegister: false,
slave: 0,
};
var DEFAULT_USB_CONFIG = {
aliases: [],
};
function tapnpassConfigJsonToApi(jsonConfig) {
return {
modbus: jsonConfig.modbus || DEFAULT_MODBUS_CONFIG,
serial: {
baudRate: jsonConfig.serial.baudRate,
bitParity: toEnum(jsonConfig.serial.bitParity, target.SerialSettings.BitParity),
dataBits: toEnum(jsonConfig.serial.dataBits, target.SerialSettings.DataBits),
handshakeDelimiter: toEnum(jsonConfig.serial.handshakeDelimiter, target.SerialSettings.HandshakeDelimiter),
hardwareFlowControl: toEnum(jsonConfig.serial.hardwareFlowControl, target.SerialSettings.HardwareFlowControl),
identification: jsonConfig.serial.identification,
ledStatus: jsonConfig.serial.ledStatus,
physicalPort: toEnum(jsonConfig.serial.physicalPort, target.SerialSettings.PhysicalPort),
stopBits: toEnum(jsonConfig.serial.stopBits, target.SerialSettings.StopBits),
timeout: jsonConfig.serial.timeout,
},
usb: jsonConfig.usb || DEFAULT_USB_CONFIG,
};
}
function canConfigJsonToApi(canConfigJson) {
var canConfigApi = {
code: core.converters.uint32.decode(configValueToBytes(canConfigJson.code)),
mask: core.converters.uint32.decode(configValueToBytes(canConfigJson.mask)),
filter: toEnum(canConfigJson.filter, target.TargetCanProtocolConfiguration.Filter),
frequency: canConfigJson.frequency,
mode: toEnum(canConfigJson.mode, target.TargetCanProtocolConfiguration.Mode),
};
return canConfigApi;
}
var __awaiter$1 = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
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) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var variableMetaConverter = new variable.VariableMetaConfigConverter();
var IGNORE_KEYS = ['version', 'tap.security'];
var USER_CREATE_KEY = 'data.profiles[]';
var CREATE_VARIABLE_CONFIG_KEY = 'data.variables[]';
function isHexString(input) {
if (typeof input !== 'string') {
return false;
}
return !!input.match(/^(0x)?([a-fA-F0-9])*$/);
}
function tapConfigToServiceCalls(config, options) {
var _a;
function addCalls(calls, newCalls) {
if (Array.isArray(newCalls)) {
calls.push.apply(calls, __spreadArray([], __read(newCalls)));
}
else {
calls.push(newCalls);
}
}
function createWriteConfigCall(key, callContext) {
if (!(key in WRITE_CONFIGURATOR_CONFIG)) {
throw new Error("Invalid API configuration. Configuration key \"" + key + "\" does not exist");
}
var callFactory = WRITE_CONFIGURATOR_CONFIG[key];
return callFactory(callContext);
}
function baseConfigObjectToCalls(entry, configKey, pathParameter) {
var e_1, _l;
var calls = [];
if (entry === undefined) {
return calls;
}
else if (Array.isArray(entry)) {
var newConfigKey = configKey + '[]';
try {
for (var entry_1 = __values(entry), entry_1_1 = entry_1.next(); !entry_1_1.done; entry_1_1 = entry_1.next()) {
var itemValue = entry_1_1.value;
if (itemValue.id || itemValue.id === 0) {
pathParameter = itemValue.id;
}
if (pathParameter === undefined) {
throw new Error("Item must have an id for key \"" + newConfigKey);
// TODO we need to know parent profile ?
}
// If there is a create instance function
if (newConfigKey in WRITE_CONFIGURATOR_CONFIG) {
if (newConfigKey === USER_CREATE_KEY &&
isSpecialProfileId(pathParameter)) {
// If it's a special user profile, we dont need the create call
}
else {
// throw new Error(`Missing create method for config key "${newConfigKey}"`);
var createBody = void 0;
if (newConfigKey === CREATE_VARIABLE_CONFIG_KEY) {
if (itemValue.metaDataLength) {
createBody = itemValue.metaDataLength;
}
else if (itemValue.rawMeta) {
createBody = itemValue.rawMeta.length;
}
}
var createCallParam = {
firmwareVersion: options.firmwareVersion,
service: options.service,
value: createBody,
param: pathParameter,
};
if (createBody === undefined) {
delete createCallParam.value;
}
try {
var newCalls = WRITE_CONFIGURATOR_CONFIG[newConfigKey](createCallParam);
addCalls(calls, newCalls);
}
catch (err) {
var error = err;
throw exports.TapConfiguratorError.internalError("Cannot generate configuration requests from configuration key " + newConfigKey + ". Cause: " + error.message, error);
}
}
}
calls.push.apply(calls, __spreadArray([], __read(baseConfigObjectToCalls(itemValue, newConfigKey, pathParameter))));
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (entry_1_1 && !entry_1_1.done && (_l = entry_1.return)) _l.call(entry_1);
}
finally { if (e_1) throw e_1.error; }
}
}
else {
if (configKey + ".$" in WRITE_CONFIGURATOR_CONFIG) {
try {
addCalls(calls, createWriteConfigCall(configKey + ".$", {
firmwareVersion: options.firmwareVersion,
service: options.service,
value: entry,
param: pathParameter,
config: config,
}));
}
catch (err) {
var error = err;
throw exports.TapConfiguratorError.internalError("Cannot generate create resource request for configuration key " + configKey + " for identifier \"" + pathParameter + "\". Cause: " + error.message, error);
}
}
else {
for (var subKey in entry) {
var newConfigKey = configKey ? configKey + "." + subKey : subKey;
if (newConfigKey === CREATE_VARIABLE_CONFIG_KEY + ".metaDataLength") {
continue;
}
var value = entry[subKey];
// We skip version key as it's a special key
if (value === undefined) {
continue;
}
else if (IGNORE_KEYS.indexOf(newConfigKey) >= 0) {
continue;
}
else if (pathParameter !== undefined &&
subKey === 'id' &&
value === pathParameter) {
// Skip id field
continue;
}
else if (newConfigKey in WRITE_CONFIGURATOR_CONFIG) {
var callContext = {
firmwareVersion: options.firmwareVersion,
service: options.service,
value: value,
param: pathParameter,
};
addCalls(calls, createWriteConfigCall(newConfigKey, callContext));
}
else if (typeof value === 'object') {
calls.push.apply(calls, __spreadArray([], __read(baseConfigObjectToCalls(value, newConfigKey, pathParameter))));
}
else {
throw new Error("Invalid config key \"" + newConfigKey + "\" with value " + value + ". " + (pathParameter ? "Current path parameter: " + pathParameter : ''));
}
}
}
}
return calls;
}
var flattenConfig = toFlatTapConfig(config, options);
var service = options.service;
var calls = [
service.interface.putConfigVersionCall('255.255.65535'),
];
var security = ((_a = config.tap) === null || _a === void 0 ? void 0 : _a.security) || {};
if (security.scramActivated) {
// Usually security options are encoded on 2 bytes
// However to enable scram during configuration, we must give 0x10 value
// Don't know why
calls.push({
method: api.TapRequestFrame.MethodType.PUT,
path: '/1024//6',
body: Uint8Array.from([0x10]),
});
}
calls.push.apply(calls, __spreadArray([], __read(baseConfigObjectToCalls(flattenConfig, '', undefined))));
if (security.scramActivated) {
security.hashPassword = true;
}
calls.push(service.interface.putSecurityOptionsCall(security));
calls.push(service.interface.putConfigVersionCall(config.version || '1.0.0'));
return calls;
}
function arrayPadEnd(data, length, padValue) {
if (padValue === void 0) { padValue = 0; }
if (data.length >= length) {
return data;
}
else {
return impl.TapStreamWriter.create(length)
.writeBytes(data)
.writeBytes(new Uint8Array(length - data.length).fill(padValue, 0, length - data.length)).toBytes;
}
}
function arrayPadStart(data, length, padValue) {
if (padValue === void 0) { padValue = 0; }
if (data.length >= length) {
return data;
}
else {
return impl.TapStreamWriter.create(length)
.writeBytes(new Uint8Array(length - data.length).fill(padValue, 0, length - data.length))
.writeBytes(data).toBytes;
}
}
function invalidVariableValueError(bundle, variable, msg) {
return exports.TapConfiguratorError.invalidConfiguration("data.bundle[" + bundle.id + "].variable[" + variable.id + "].value " + msg);
}
function encodeInitialVariableValue(variable, bundle) {
var variableLength = variable.length || 1;
var variableDataType = variable.dataType === undefined
? all.VariableType.Data.UINT8
: all.VariableType.Data[variable.dataType];
var itemByteSize = data.variableDataTypeToByteSize(variableDataType);
function _encodeItem(value, index) {
if (index === void 0) { index = 0; }
var result;
if (value instanceof Uint8Array) {
result = value;
}
else if (isHexString(value)) {
result = byteConverter.hexStringToBuffer(value);
}
else if (typeof value === 'number') {
var converter = data.getConverterFromVariableType(variableDataType, 1);
if (!converter) {
throw invalidVariableValueError(bundle, variable, "cannot be converted to a buffer. No registered converter exist for this variable type.");
}
result = converter.encode(value);
}
else {
throw invalidVariableValueError(bundle, variable, "has type " + typeof value + " which is not supported by the configurator");
}
if (result.length > itemByteSize) {
throw invalidVariableValueError(bundle, variable, "at index " + index + " is on " + result.length + " bytes but expecting a maximum length of " + itemByteSize + " byte(s)");
}
else {
result = arrayPadStart(result, itemByteSize);
}
return result;
}
var encodedValue;
if (typeof variable.value === 'string' &&
variableDataType === all.VariableType.Data.ASCII) {
encodedValue = all.converters.ascii.encode(variable.value);
}
else if (Array.isArray(variable.value)) {
var buffers = variable.value.map(function (v, index) {
return _encodeItem(v, index);
});
encodedValue = impl.TapStreamWriter.mergeArrays.apply(impl.TapStreamWriter, __spreadArray([], __read(buffers)));
}
else {
encodedValue = _encodeItem(variable.value);
}
var byteLength = variableLength * itemByteSize;
if (encodedValue.length > byteLength) {
throw invalidVariableValueError(bundle, variable, "is encoded on " + encodedValue.length + " byte(s) but you have declared a maximum length of " + byteLength + " byte(s)");
}
return arrayPadEnd(encodedValue, byteLength);
}
function toVariableFlatConfig(variable, bundle) {
var variableCopy = utility.deepCopy(variable);
if (variableCopy.length === undefined) {
variableCopy.length = 1;
}
var variableFlatConfig = variableCopy;
delete variableCopy.dataType;
delete variableCopy.domain;
variableFlatConfig.bundleId = bundle.id;
if (variableFlatConfig.rawMeta !== undefined) {
variableFlatConfig.rawMeta =
typeof variableFlatConfig.rawMeta === 'string'
? byteConverter.hexStringToBuffer(variableFlatConfig.rawMeta)
: variableFlatConfig.rawMeta;
}
else if (variableCopy.meta) {
variableFlatConfig.rawMeta = variableMetaConverter.encode(variableCopy.meta);
delete variableCopy.meta;
}
variableFlatConfig.type = {
domain: variable.domain !== undefined ? variable.domain : 'TARGET',
data: variable.dataType !== undefined ? variable.dataType : 'UINT8',
};
if (variable.value !== undefined && variable.value !== null) {
variableFlatConfig.value = encodeInitialVariableValue(variable, bundle);
}
return variableFlatConfig;
}
function toFlatTapConfig(config, options) {
var e_2, _l, e_3, _m, e_4, _o, e_5, _p, e_6, _q, e_7, _r, e_8, _s;
var _a, _b, _c, _d, _e, _f, _g;
var configCopy = utility.deepCopy(config);
var flatProfiles = [];
if (configCopy.target) {
delete configCopy.target.type;
}
if (configCopy.data) {
// Flaten profiles
if (configCopy.data.profiles) {
try {
for (var _t = __values((_a = configCopy.data) === null || _a === void 0 ? void 0 : _a.profiles), _u = _t.next(); !_u.done; _u = _t.next()) {
var profile = _u.value;
var flatenProfile = profile;
if (flatenProfile.id === undefined) {
flatenProfile.id = getProfileIdFromConfig(flatenProfile);
}
if (isSpecialProfileId(flatenProfile.id)) {
delete flatenProfile.username;
}
var subProfiles = flatenProfile.users || [];
delete flatenProfile.users;
flatProfiles.push(flatenProfile);
try {
for (var subProfiles_1 = (e_3 = void 0, __values(subProfiles)), subProfiles_1_1 = subProfiles_1.next(); !subProfiles_1_1.done; subProfiles_1_1 = subProfiles_1.next()) {
var subProfile = subProfiles_1_1.value;
subProfile.alias = flatenProfile.id;
flatProfiles.push(subProfile);
if (isSpecialProfileId(subProfile.id)) {
delete subProfile.username;
}
}
}
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {
try {
if (subProfiles_1_1 && !subProfiles_1_1.done && (_m = subProfiles_1.return)) _m.call(subProfiles_1);
}
finally { if (e_3) throw e_3.error; }
}
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_u && !_u.done && (_l = _t.return)) _l.call(_t);
}
finally { if (e_2) throw e_2.error; }
}
}
// Flaten acls and special features
var flatSpecialFeatures = [];
var flatVariables = [];
if (configCopy.data.bundles) {
try {
for (var _v = __values(configCopy.data.bundles), _w = _v.next(); !_w.done; _w = _v.next()) {
var bundle = _w.value;
var acls = bundle.acls || {};
delete bundle.acls;
var flatAcls = [];
var _loop_1 = function (username) {
var acl = acls[username];
var profile = flatProfiles.find(function (p) { return p.username === username; });
if (!profile) {
profile = SPECIAL_USERS.find(function (p) { return p.username === username; });
if (!profile) {
throw new Error("Cannot find profile with username \"" + username + "\""); // TODO proper error
}
}
flatAcls.push({
groupId: profile.id,
read: acl.read,
write: acl.write,
});
};
for (var username in acls) {
_loop_1(username);
}
if (flatAcls.length > 0) {
bundle.acl = flatAcls;
}
var variables = bundle.variables || [];
delete bundle.variables;
try {
for (var variables_1 = (e_5 = void 0, __values(variables)), variables_1_1 = variables_1.next(); !variables_1_1.done; variables_1_1 = variables_1.next()) {
var variable = variables_1_1.value;
flatVariables.push(toVariableFlatConfig(variable, bundle));
}
}
catch (e_5_1) { e_5 = { error: e_5_1 }; }
finally {
try {
if (variables_1_1 && !variables_1_1.done && (_p = variables_1.return)) _p.call(variables_1);
}
finally { if (e_5) throw e_5.error; }
}
var features = bundle.features || [];
delete bundle.features;
var _loop_2 = function (featureKey) {
var featureId = enumKeyToEnumValue(featureKey, tap.SpecialFeature);
if (flatSpecialFeatures.find(function (f) { return f.id === featureId; })) {
throw new Error("Special feature \"" + featureId + "\" has already be given to another bundle");
}
flatSpecialFeatures.push({
id: featureId,
bundleId: bundle.id,
});
};
try {
for (var features_1 = (e_6 = void 0, __values(features)), features_1_1 = features_1.next(); !features_1_1.done; features_1_1 = features_1.next()) {
var featureKey = features_1_1.value;
_loop_2(featureKey);
}
}
catch (e_6_1) { e_6 = { error: e_6_1 }; }
finally {
try {
if (features_1_1 && !features_1_1.done && (_q = features_1.return)) _q.call(features_1);
}
finally { if (e_6) throw e_6.error; }
}
}
}
catch (e_4_1) { e_4 = { error: e_4_1 }; }
finally {
try {
if (_w && !_w.done && (_o = _v.return)) _o.call(_v);
}
finally { if (e_4) throw e_4.error; }
}
}
if (flatSpecialFeatures.length > 0) {
configCopy.data.features = flatSpecialFeatures;
}
if (flatVariables.length > 0) {
configCopy.data.variables = flatVariables;
}
}
if ((_c = (_b = config.tap) === null || _b === void 0 ? void 0 : _b.security) === null || _c === void 0 ? void 0 : _c.scramActivated) {
if (!configCopy.tap) {
configCopy.tap = {};
}
if (!configCopy.tap.scram) {
configCopy.tap.scram = {};
}
if (!configCopy.tap.scram.hashIteration) {
configCopy.tap.scram.hashIteration = DEFAULT_HASH_ITERATION_COUNT;
}
}
var hashIteration = (_e = (_d = configCopy.tap) === null || _d === void 0 ? void 0 : _d.scram) === null || _e === void 0 ? void 0 : _e.hashIteration;
var _loop_3 = function (specialProfile) {
if (!flatProfiles.find(function (p) { return p.id === specialProfile.id; })) {
flatProfiles.push({
id: specialProfile.id,
password: specialProfile.password || specialProfile.username,
lifeTime: specialProfile.lifeTime || 30,
});
}
};
try {
for (var _x = __values([ADMIN_USER, SUPERVISOR_USER]), _y = _x.next(); !_y.done; _y = _x.next()) {
var specialProfile = _y.value;
_loop_3(specialProfile);
}
}
catch (e_7_1) { e_7 = { error: e_7_1 }; }
finally {
try {
if (_y && !_y.done && (_r = _x.return)) _r.call(_x);
}
finally { if (e_7) throw e_7.error; }
}
try {
for (var flatProfiles_1 = __values(flatProfiles), flatProfiles_1_1 = flatProfiles_1.next(); !flatProfiles_1_1.done; flatProfiles_1_1 = flatProfiles_1.next()) {
var profile = flatProfiles_1_1.value;
prepareUserPassword(profile, ((_f = configCopy === null || configCopy === void 0 ? void 0 : configCopy.tap) === null || _f === void 0 ? void 0 : _f.security) || {}, function (input) {
if (!hashIteration) {
throw exports.TapConfiguratorError.internalError("Hash iteration value must be set");
}
var salt = (options === null || options === void 0 ? void 0 : options.saltGenerator)
? options.saltGenerator()
: auth.DEFAULT_SCRAM_SALT_GENERATOR();
return auth.ScramAuth.createScramPasswordKey(input, {
salt: salt,
iterationNumber: hashIteration,
});
});
}
}
catch (e_8_1) { e_8 = { error: e_8_1 }; }
finally {
try {
if (flatProfiles_1_1 && !flatProfiles_1_1.done && (_s = flatProfiles_1.return)) _s.call(flatProfiles_1);
}
finally { if (e_8) throw e_8.error; }
}
if (!configCopy.data) {
configCopy.data = {};
}
configCopy.data.profiles = flatProfiles;
if ((_g = configCopy.application) === null || _g === void 0 ? void 0 : _g.uri) {
if (typeof configCopy.application.uri === 'object') {
var appUri = configCopy.application.uri;
configCopy.application.uri = "" + tap.AppPathType[appUri.type] + appUri.value;
}
}
// We must set codeSize as Tap will change where JVM code is stored according to the code size
if (configCopy.jvm && configCopy.jvm.code) {
var codeSize = configCopy.jvm.codeSize === undefined
? computeJvmCodeByteSize(configCopy.jvm.code)
: configCopy.jvm.codeSize;
delete configCopy.jvm.codeSize;
configCopy.jvm = Object.assign({
// to make sure that code size request is done first
codeSize: codeSize
}, configCopy.jvm);
}
return configCopy;
}
function computeJvmCodeByteSize(input) {
if (!input) {
return 0;
}
if (typeof input === 'string') {
var length = input.length / 2;
if (input.startsWith('0x')) {
length -= 1;
}
return length;
}
else {
return input.length;
}
}
function prepareUserPassword(profile, securityConfig, scramPasswordGenerator) {
if (profile.password) {
if (profile.key) {
throw exports.TapConfiguratorError.invalidConfiguration("You cannot specify both password and passwordKey for profile configuration. Specify only one of those two options.");
}
if (securityConfig.scramActivated) {
var passwordBytes = scramPasswordGenerator(profile.password);
// debug(
// `Writing SCRAM password for user id ${userId} with hash: ${bufferToHexString(passwordBytes)}`
// );
delete profile.password;
profile.key = passwordBytes;
}
else if (securityConfig.hashPassword) {
var passwordBytes = auth.hashLoginPassword(profile.password);
// debug(
// `Writing password for user id ${userId} with hash: ${bufferToHexString(
// passwordBytes
// )}`
// );
delete profile.password;
profile.key = passwordBytes;
}
else {
// debug(
// `Writing password for user id ${userId} without hash: ${password}`
// );
// OK nothing to do
}
}
// console.log('profile.passwordKey', typeof profile.passwordKey, profile.passwordKey?.constructor?.name);
}
function stepEvent$1(observer, step, context, extraData) {
observer.next(Object.assign({ step: step, progress: {
loaded: context.index + 1,
total: context.total,
} }, (extraData || {})));
}
/**
* Configure tap from a configuration file schema
*
*/
exports.TapConfiguratorWriter = /** @class */ (function () {
function TapConfiguratorWriter(options, host) {
if (options === void 0) { options = {
delayMs: 400,
throwOnNotImplementedConfigKey: false,
}; }
this.options = options;
this.host = host;
}
TapConfiguratorWriter.prototype.createConfiguratorForTap = function (tap, config, options) {
return __awaiter$1(this, void 0, void 0, function () {
var firmwareVersion;
return __generator(this, function (_l) {
switch (_l.label) {
case 0: return [4 /*yield*/, tap.service.device.getFirmwareVersion()];
case 1:
firmwareVersion = (_l.sent()).body();
return [2 /*return*/, this.configure(tap, firmwareVersion, config, options)];
}
});
});
};
TapConfiguratorWriter.prototype.configure = function (tap, firmwareVersion, config, options) {
var _this = this;
var _a, _b;
var configureContext = {
tap: tap,
options: config.meta || {},
tapConfig: config.config,
};
var operations = [];
config = this._adaptConfigurationToCurrentVersion(config);
if (!(options === null || options === void 0 ? void 0 : options.skipSchemaValidation)) {
operations.push(function (observer, context) { return __awaiter$1(_this, void 0, void 0, function () {
return __generator(this, function (_l) {
stepEvent$1(observer, TapConfiguratorWriter.Step.validatesConfig, context);
validateTapConfiguratorConfig(config);
return [2 /*return*/];
});
}); });
}
if (!configureContext.options.skipFactoryReset) {
operations.push(function (observer, context) { return __awaiter$1(_this, void 0, void 0, function () {
return __generator(this, function (_l) {
switch (_l.label) {
case 0:
stepEvent$1(observer, TapConfiguratorWriter.Step.factoryReset, context);
return [4 /*yield*/, tap.service.device.factoryReset()];
case 1:
(_l.sent()).successful();
return [2 /*return*/];
}
});
}); });
}
var useScram = !!((_b = (_a = configureContext.tapConfig.tap) === null || _a === void 0 ? void 0 : _a.security) === null || _b === void 0 ? void 0 : _b.scramActivated);
if (useScram) {
operations.push(function (observer, context) { return __awaiter$1(_this, void 0, void 0, function () {
return __generator(this, function (_l) {
switch (_l.label) {
case 0:
stepEvent$1(observer, TapConfiguratorWriter.Step.enableSecureCom, context);
if (!useScram) return [3 /*break*/, 2];
return [4 /*yield*/, tap.encryption.start()];
case 1:
_l.sent();
_l.label = 2;
case 2: return [2 /*return*/];
}
});
}); });
}
var calls = tapConfigToServiceCalls(configureContext.tapConfig, {
firmwareVersion: firmwareVersion,
service: tap.service,
});
// operations.push(async (observer, context) => {
// observer.next({
// step: TapConfigurator.Step.
// } as TapConfigurator.Event);
// const firmwareVersion = (await context.tap.service.device.getFirmwareVersion()).body();
// });
// operations.push(
// async (observer, context) => {
// stepEvent(observer, TapConfiguratorWriter.Step.setupConfigurationState, context);
// await this.setupConfigState(configureContext.tap);
// }
// );
// if (useScram) {
// operations.push(async (observer, context) => {
// // To write user password keys, we need to put scram configuration first
// stepEvent(observer, TapConfiguratorWriter.Step.writeSecurityOptions, context);
// tap.encryption.pause();
// (await tap.service.interface.putSecurityOptions({
// scramActivated: true
// } as SecurityOptions)).successful();
// tap.encryption.resume();
// });
// }
this.addConfigurCalls(configureContext, calls, operations);
// operations.push(
// async (observer, context) => {
// stepEvent(observer, TapConfiguratorWriter.Step.applyConfig, context);
// await this.applyConfig(configureContext.tap, configureContext.tapConfig.version || '1.0.0');
// }
// );
operations.push(function (observer, context) { return __awaiter$1(_this, void 0, void 0, function () {
return __generator(this, function (_l) {
switch (_l.label) {
case 0:
stepEvent$1(observer, TapConfiguratorWriter.Step.logout, context);
return [4 /*yield*/, configureContext.tap.auth.logout()];
case 1:
_l.sent();
tap.auth.clearCache();
return [2 /*return*/];
}
});
}); });
return taskManager.StepOperations.sequential(operations);
};
TapConfiguratorWriter.prototype.setupConfigState = function (tap) {
return __awaiter$1(this, void 0, void 0, function () {
var state;
return __generator(this, function (_l) {
switch (_l.label) {
case 0: return [4 /*yield*/, tap.service.firmware.getState()];
case 1:
state = (_l.sent()).body();
if (state !== all.FirmwareState.NORMAL && state !== all.FirmwareState.LEGACY) {
throw exports.TapConfiguratorError.unexpectedFirmwareState(state);
}
return [4 /*yield*/, tap.service.interface.putConfigVersion('255.255.65535')];
case 2:
(_l.sent()).successful();
return [2 /*return*/];
}
});
});
};
// TODO move from here
TapConfiguratorWriter.prototype.isConfigured = function (tap) {
return __awaiter$1(this, void 0, void 0, function () {
var configVersionCalled, intValue;
return __generator(this, function (_l) {
switch (_l.label) {
case 0: return [4 /*yield*/, tap.service.interface.getConfigVersion()];
case 1:
configVersionCalled = _l.sent();
configVersionCalled.successful();
intValue = configVersionCalled.body(impl.NumberConverter.uint32());
return [2 /*return*/, intValue !== 0];
}
});
});
};
/***
*
*/
TapConfiguratorWriter.prototype.applyConfig = function (tap, newVersion) {
if (newVersion === void 0) { newVersion = '1.0.0'; }
return __awaiter$1(this, void 0, void 0, function () {
return __generator(this, function (_l) {
switch (_l.label) {
case 0: return [4 /*yield*/, this.sleep(this.options.delayMs)];
case 1:
_l.sent();
return [4 /*yield*/, tap.service.interface.putConfigVersion(newVersion)];
case 2:
(_l.sent()).successful();
return [4 /*yield*/, this.sleep(this.options.delayMs)];
case 3:
_l.sent();
return [4 /*yield*/, tap.service.interface.reloadConfig()];
case 4:
(_l.sent()).successful();
return [4 /*yield*/, this.sleep(this.options.delayMs)];
case 5:
_l.sent();
return [2 /*return*/];
}
});
});
};
TapConfiguratorWriter.prototype.addConfigurCalls = function (configureContext, calls, operations) {
var _this = this;
calls.forEach(function (callOrError, index) {
operations.push(function (observer, context) { return __awaiter$1(_this, void 0, void 0, function () {
var stepProgress, err_1, responseStatusError;
return __generator(this, function (_l) {
switch (_l.label) {
case 0:
stepProgress = {
total: calls.length,
loaded: index + 1,
};
if (!(callOrError instanceof Error)) return [3 /*break*/, 1];
stepEvent$1(observer, TapConfiguratorWriter.Step.executeCall, context, {
error: callOrError,
stepProgress: stepProgress,
});
return [3 /*break*/, 5];
case 1:
stepEvent$1(observer, TapConfiguratorWriter.Step.executeCall, context, {
stepProgress: stepProgress,
call: callOrError,
});
_l.label = 2;
case 2:
_l.trys.push([2, 4, , 5]);
return [4 /*yield*/, configureContext.tap.lwm2m.execute(callOrError)];
case 3:
(_l.sent()).successful();
return [3 /*break*/, 5];
case 4:
err_1 = _l.sent();
if (!this.options.throwOnNotImplementedConfigKey &&
error.isCodeError(tap.TapError.Code.ResponseStatusError, err_1)) {
responseStatusError = err_1;
if (responseStatusError.response.status ===
api.ResultCode.NOT_IMPLEMENTED) {
stepEvent$1(observer, TapConfiguratorWriter.Step.executeCall, context, {
error: err_1,
stepProgress: stepProgress,
});
return [2 /*return*/];
}
}
throw err_1;
case 5: return [2 /*return*/];
}
});
}); });
});
};
TapConfiguratorWriter.prototype.sleep = function (delayMs) {
return utility.sleep(delayMs);
};
TapConfiguratorWriter.prototype._adaptConfigurationToCurrentVersion = function (config) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
if (config.config.wireless) {
var blePairing = undefined;
var nfcPairingMode = void 0;
if (((_c = (_b = (_a = config.config.wireless) === null || _a === void 0 ? void 0 : _a.protocols) === null || _b === void 0 ? void 0 : _b.nfc) === null || _c === void 0 ? void 0 : _c.pairingMode) !== undefined) {
nfcPairingMode = config.config.wireless.protocols.nfc.pairingMode;
delete config.config.wireless.protocols.nfc.pairingMode;
}
if (((_f = (_e = (_d = config.config.wireless) === null || _d === void 0 ? void 0 : _d.protocols) === null || _e === void 0 ? void 0 : _e.ble) === null || _f === void 0 ? void 0 : _f.pairing) !== undefined) {
blePairing = (_j = (_h = (_g = config.config.wireless) === null || _g === void 0 ? void 0 : _g.protocols) === null || _h === void 0 ? void 0 : _h.ble) === null || _j === void 0 ? void 0 : _j.pairing;
(_k = config.config.wireless.protocols.ble) === null || _k === void 0 ? true : delete _k.pairing;
}
if (!config.config.wireless.options) {
config.config.wireless.options = {};
}
if (blePairing !== undefined || nfcPairingMode !== undefined) {
config.config.wireless.options.pairing = {
nfcPairingMode: nfcPairingMode,
blePairing: blePairing,
};
}
}
return config;
};
return TapConfiguratorWriter;
}());
(function (TapConfiguratorWriter) {
var Step;
(function (Step) {
Step["validatesConfig"] = "TapConfiguratorStepValidatesConfig";
Step["enableSecureCom"] = "TapConfiguratorStepenableSecureCommunication";
Step["factoryReset"] = "TapConfiguratorStepFactoryReset";
Step["setupConfigurationState"] = "TapConfiguratorStepSetupConfigurationState";
Step["executeCall"] = "TapConfiguratorStepExecuteCall";
Step["logout"] = "TapConfiguratorSteplogout";
Step["applyConfig"] = "TapConfiguratorStepApplyConfig";
Step["writeSecurityOptions"] = "TapConfiguratorStepWriteSecurityOptions";
})(Step = TapConfiguratorWriter.Step || (TapConfiguratorWriter.Step = {}));
})(exports.TapConfiguratorWriter || (exports.TapConfiguratorWriter = {}));
/**
* Generated file. Do not edit
*/
var ɵ0$1 = function (context) {
return context.service.interface.getApplicationDataCall();
}, ɵ1 = function (context) {
return context.service.interface.getAppNameCall();
}, ɵ2 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.113')) {
return new ConfigKeyNotSupportedByFirmwareVersion('application.productCode', context.firmwareVersion, {
minApiVersion: '1.113',
maxApiVersion: undefined,
});
}
}
return context.service.interface.getProductCodeCall();
}, ɵ3 = function (context) {
return context.service.interface.getUniversalLinkCall();
}, ɵ4 = function (context) {
return context.service.interface.getAppPathCall();
}, ɵ5 = function (context) {
return context.service.cloud.getDataLogPublishTopicCall();
}, ɵ6 = function (context) {
return context.service.cloud.getDataLogSubscribeTopicCall();
}, ɵ7 = function (context) {
return context.service.cloud.getDataLogUploadPeriodCall();
}, ɵ8 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionLessThanOrEqual(context.firmwareVersion, '1.103')) {
return new ConfigKeyNotSupportedByFirmwareVersion('cloud.mqtt.brokerPort', context.firmwareVersion, {
minApiVersion: undefined,
maxApiVersion: '1.103',
});
}
}
return context.service.cloud.getMqttBrokerPortCall();
}, ɵ9 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionLessThanOrEqual(context.firmwareVersion, '1.103')) {
return new ConfigKeyNotSupportedByFirmwareVersion('cloud.mqtt.clientId', context.firmwareVersion, {
minApiVersion: undefined,
maxApiVersion: '1.103',
});
}
}
return context.service.cloud.getMqttClientIdCall();
}, ɵ10 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionLessThanOrEqual(context.firmwareVersion, '1.103')) {
return new ConfigKeyNotSupportedByFirmwareVersion('cloud.mqtt.password', context.firmwareVersion, {
minApiVersion: undefined,
maxApiVersion: '1.103',
});
}
}
return context.service.cloud.getMqttPasswordCall();
}, ɵ11 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionLessThanOrEqual(context.firmwareVersion, '1.103')) {
return new ConfigKeyNotSupportedByFirmwareVersion('cloud.mqtt.username', context.firmwareVersion, {
minApiVersion: undefined,
maxApiVersion: '1.103',
});
}
}
return context.service.cloud.getMqttUsernameCall();
}, ɵ12 = function (context) {
return context.service.cloud.getPlatformCall();
}, ɵ13 = function (context) {
return context.service.interface.getConfigFormatVersionCall();
}, ɵ14 = function (context) {
return context.service.bundle.getDataLogCryptoGroupIdCall(context.param);
}, ɵ15 = function (context) {
return context.service.bundle.getDataLogPeriodCall(context.param);
}, ɵ16 = function (context) {
return context.service.bundle.getNameCall(context.param);
}, ɵ17 = function (context) {
return context.service.group.getAliasCall(context.param);
}, ɵ18 = function (context) {
return context.service.group.getSessionLifetimeCall(context.param);
}, ɵ19 = function (context) {
return context.service.group.getNameCall(context.param);
}, ɵ20 = function (context) {
return context.service.variable.getVariableAddressCall(context.param);
}, ɵ21 = function (context) {
return context.service.variable.getBundleIdCall(context.param);
}, ɵ22 = function (context) {
return context.service.variable.getNumberOfElementsCall(context.param);
}, ɵ23 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.73')) {
return new ConfigKeyNotSupportedByFirmwareVersion('data.variables[].meta', context.firmwareVersion, {
minApiVersion: '1.73',
maxApiVersion: undefined,
});
}
}
return context.service.variable.getMetaCall(context.param);
}, ɵ24 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.73')) {
return new ConfigKeyNotSupportedByFirmwareVersion('data.variables[].rawMeta', context.firmwareVersion, {
minApiVersion: '1.73',
maxApiVersion: undefined,
});
}
}
return context.service.variable.getRawMetaCall(context.param);
}, ɵ25 = function (context) {
return context.service.variable.getTypeCall(context.param);
}, ɵ26 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.90')) {
return new ConfigKeyNotSupportedByFirmwareVersion('jvm.codeSize', context.firmwareVersion, {
minApiVersion: '1.90',
maxApiVersion: undefined,
});
}
}
return context.service.jvm.getCodeSizeCall();
}, ɵ27 = function (context) {
return context.service.jvm.getProfileIdCall();
}, ɵ28 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '2.7')) {
return new ConfigKeyNotSupportedByFirmwareVersion('ports.ethernet.gatewayIp', context.firmwareVersion, {
minApiVersion: '2.7',
maxApiVersion: undefined,
});
}
}
return context.service.ethernet.getGatewayIpCall();
}, ɵ29 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '2.7')) {
return new ConfigKeyNotSupportedByFirmwareVersion('ports.ethernet.ip', context.firmwareVersion, {
minApiVersion: '2.7',
maxApiVersion: undefined,
});
}
}
return context.service.ethernet.getIpCall();
}, ɵ30 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '2.7')) {
return new ConfigKeyNotSupportedByFirmwareVersion('ports.ethernet.ipMask', context.firmwareVersion, {
minApiVersion: '2.7',
maxApiVersion: undefined,
});
}
}
return context.service.ethernet.getIpMaskCall();
}, ɵ31 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '2.11')) {
return new ConfigKeyNotSupportedByFirmwareVersion('tap.autoRebootTimeout', context.firmwareVersion, {
minApiVersion: '2.11',
maxApiVersion: undefined,
});
}
}
return context.service.interface.getAutoRebootTimeoutCall();
}, ɵ32 = function (context) {
return context.service.interface.getMaxLowPowerTimeCall();
}, ɵ33 = function (context) {
return context.service.interface.getPowerOptimisationLevelCall();
}, ɵ34 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '2.15')) {
return new ConfigKeyNotSupportedByFirmwareVersion('tap.powerOptimizationOptions', context.firmwareVersion, {
minApiVersion: '2.15',
maxApiVersion: undefined,
});
}
}
return context.service.interface.getPowerOptimisationOptionsCall();
}, ɵ35 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.11')) {
return new ConfigKeyNotSupportedByFirmwareVersion('tap.scram.hashIteration', context.firmwareVersion, {
minApiVersion: '1.11',
maxApiVersion: undefined,
});
}
}
return context.service.scram.getHashIterationCall();
}, ɵ36 = function (context) {
return context.service.interface.getSecurityOptionsCall();
}, ɵ37 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.107')) {
return new ConfigKeyNotSupportedByFirmwareVersion('tap.time.ntpServer', context.firmwareVersion, {
minApiVersion: '1.107',
maxApiVersion: undefined,
});
}
}
return context.service.time.getNtpServerCall();
}, ɵ38 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.107')) {
return new ConfigKeyNotSupportedByFirmwareVersion('tap.time.zone', context.firmwareVersion, {
minApiVersion: '1.107',
maxApiVersion: undefined,
});
}
}
return context.service.time.getTimeZoneCall();
}, ɵ39 = function (context) {
return context.service.target.getFirmwareVersionCall();
}, ɵ40 = function (context) {
return context.service.target.getModbusDefaultSlaveAddressCall();
}, ɵ41 = function (context) {
return context.service.target.getProtocolCall();
}, ɵ42 = function (context) {
return context.service.interface.getConfigVersionCall();
}, ɵ43 = function (context) {
return context.service.interface.getAuthorizedHostProtocolCall();
}, ɵ44 = function (context) {
return context.service.interface.getHostInactivityPeriodCall();
}, ɵ45 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '2.13')) {
return new ConfigKeyNotSupportedByFirmwareVersion('wireless.options.network', context.firmwareVersion, {
minApiVersion: '2.13',
maxApiVersion: undefined,
});
}
}
return context.service.interface.getNetworkOptionsCall();
}, ɵ46 = function (context) {
return context.service.interface.getPairingOptionsCall();
}, ɵ47 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '2.7')) {
return new ConfigKeyNotSupportedByFirmwareVersion('wireless.protocols.ethernet.dnsIp', context.firmwareVersion, {
minApiVersion: '2.7',
maxApiVersion: undefined,
});
}
}
return context.service.ethernet.getDnsIpCall();
}, ɵ48 = function (context) {
return context.service.lora.getConfigCall();
}, ɵ49 = function (context) {
return context.service.lora.getIdsCall();
}, ɵ50 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '2.11')) {
return new ConfigKeyNotSupportedByFirmwareVersion('wireless.protocols.lte.applicationData', context.firmwareVersion, {
minApiVersion: '2.11',
maxApiVersion: undefined,
});
}
}
return context.service.lte.getApplicationDataCall();
}, ɵ51 = function (context) {
return context.service.mqtt.getBrokerHostnameCall();
}, ɵ52 = function (context) {
return context.service.mqtt.getBrokerPortCall();
}, ɵ53 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.86')) {
return new ConfigKeyNotSupportedByFirmwareVersion('wireless.protocols.mqtt.clientId', context.firmwareVersion, {
minApiVersion: '1.86',
maxApiVersion: undefined,
});
}
}
return context.service.mqtt.getClientIdCall();
}, ɵ54 = function (context) {
return context.service.mqtt.getPasswordCall();
}, ɵ55 = function (context) {
return context.service.mqtt.getRelayNetKeyCall();
}, ɵ56 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.86')) {
return new ConfigKeyNotSupportedByFirmwareVersion('wireless.protocols.mqtt.requestTopic', context.firmwareVersion, {
minApiVersion: '1.86',
maxApiVersion: undefined,
});
}
}
return context.service.mqtt.getRequestTopicCall();
}, ɵ57 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.107')) {
return new ConfigKeyNotSupportedByFirmwareVersion('wireless.protocols.mqtt.responseTopic', context.firmwareVersion, {
minApiVersion: '1.107',
maxApiVersion: undefined,
});
}
}
return context.service.mqtt.getResponseTopicCall();
}, ɵ58 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.86')) {
return new ConfigKeyNotSupportedByFirmwareVersion('wireless.protocols.mqtt.username', context.firmwareVersion, {
minApiVersion: '1.86',
maxApiVersion: undefined,
});
}
}
return context.service.mqtt.getUsernameCall();
}, ɵ59 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.55')) {
return new ConfigKeyNotSupportedByFirmwareVersion('wireless.protocols.nfc.autoLogProfileId', context.firmwareVersion, {
minApiVersion: '1.55',
maxApiVersion: undefined,
});
}
}
return context.service.interface.getNfcAutologProfileIdCall();
}, ɵ60 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.85')) {
return new ConfigKeyNotSupportedByFirmwareVersion('wireless.protocols.nfc.connectionPriority', context.firmwareVersion, {
minApiVersion: '1.85',
maxApiVersion: undefined,
});
}
}
return context.service.interface.getNfcConnectionPriorityCall();
}, ɵ61 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.88')) {
return new ConfigKeyNotSupportedByFirmwareVersion('wireless.protocols.wifi.countryCode', context.firmwareVersion, {
minApiVersion: '1.88',
maxApiVersion: undefined,
});
}
}
return context.service.wifi.getCountryCodeCall();
}, ɵ62 = function (context) {
return context.service.wifi.getDnsIpCall();
}, ɵ63 = function (context) {
return context.service.wifi.getGatewayIpCall();
}, ɵ64 = function (context) {
return context.service.wifi.getIpCall();
}, ɵ65 = function (context) {
return context.service.wifi.getKeyCall();
}, ɵ66 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.88')) {
return new ConfigKeyNotSupportedByFirmwareVersion('wireless.protocols.wifi.keyVisibility', context.firmwareVersion, {
minApiVersion: '1.88',
maxApiVersion: undefined,
});
}
}
return context.service.wifi.getKeyVisibilityCall();
}, ɵ67 = function (context) {
return context.service.wifi.getIpMaskCall();
}, ɵ68 = function (context) {
return context.service.wifi.getModeCall();
}, ɵ69 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '2.13')) {
return new ConfigKeyNotSupportedByFirmwareVersion('wireless.protocols.wifi.networkMode', context.firmwareVersion, {
minApiVersion: '2.13',
maxApiVersion: undefined,
});
}
}
return context.service.wifi.getNetworkModeCall();
}, ɵ70 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.88')) {
return new ConfigKeyNotSupportedByFirmwareVersion('wireless.protocols.wifi.protocol', context.firmwareVersion, {
minApiVersion: '1.88',
maxApiVersion: undefined,
});
}
}
return context.service.wifi.getProtocolCall();
}, ɵ71 = function (context) {
return context.service.wifi.getSSIDCall();
}, ɵ72 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.88')) {
return new ConfigKeyNotSupportedByFirmwareVersion('wireless.protocols.wifi.ssidVisibility', context.firmwareVersion, {
minApiVersion: '1.88',
maxApiVersion: undefined,
});
}
}
return context.service.wifi.getSSIDVisibilityCall();
}, ɵ73 = function (context) {
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '1.88')) {
return new ConfigKeyNotSupportedByFirmwareVersion('wireless.protocols.wifi.txPower', context.firmwareVersion, {
minApiVersion: '1.88',
maxApiVersion: undefined,
});
}
}
return context.service.wifi.getTxPowerCall();
};
var READ_CONFIGURATOR_CONFIG$1 = {
'application.data': ɵ0$1,
'application.name': ɵ1,
'application.productCode': ɵ2,
'application.universalLink': ɵ3,
'application.uri': ɵ4,
'cloud.dataLog.mqttPublishTopic': ɵ5,
'cloud.dataLog.mqttSubscribeTopic': ɵ6,
'cloud.dataLog.uploadPeriod': ɵ7,
'cloud.mqtt.brokerPort': ɵ8,
'cloud.mqtt.clientId': ɵ9,
'cloud.mqtt.password': ɵ10,
'cloud.mqtt.username': ɵ11,
'cloud.platform': ɵ12,
configFormatVersion: ɵ13,
'data.bundles[].dataLog.cryptoGroupId': ɵ14,
'data.bundles[].dataLog.period': ɵ15,
'data.bundles[].name': ɵ16,
'data.profiles[].alias': ɵ17,
'data.profiles[].lifeTime': ɵ18,
'data.profiles[].username': ɵ19,
'data.variables[].address': ɵ20,
'data.variables[].bundleId': ɵ21,
'data.variables[].length': ɵ22,
'data.variables[].meta': ɵ23,
'data.variables[].rawMeta': ɵ24,
'data.variables[].type': ɵ25,
'jvm.codeSize': ɵ26,
'jvm.profileId': ɵ27,
'ports.ethernet.gatewayIp': ɵ28,
'ports.ethernet.ip': ɵ29,
'ports.ethernet.ipMask': ɵ30,
'tap.autoRebootTimeout': ɵ31,
'tap.maxLowPowerTime': ɵ32,
'tap.powerOptimization': ɵ33,
'tap.powerOptimizationOptions': ɵ34,
'tap.scram.hashIteration': ɵ35,
'tap.security': ɵ36,
'tap.time.ntpServer': ɵ37,
'tap.time.zone': ɵ38,
'target.firmwareVersion': ɵ39,
'target.modbusDefaultSlaveAddress': ɵ40,
'target.protocol.type': ɵ41,
version: ɵ42,
'wireless.options.authorizedProtocols': ɵ43,
'wireless.options.inactivityTimeout': ɵ44,
'wireless.options.network': ɵ45,
'wireless.options.pairing': ɵ46,
'wireless.protocols.ethernet.dnsIp': ɵ47,
'wireless.protocols.lora.config': ɵ48,
'wireless.protocols.lora.ids': ɵ49,
'wireless.protocols.lte.applicationData': ɵ50,
'wireless.protocols.mqtt.brokerHostname': ɵ51,
'wireless.protocols.mqtt.brokerPort': ɵ52,
'wireless.protocols.mqtt.clientId': ɵ53,
'wireless.protocols.mqtt.password': ɵ54,
'wireless.protocols.mqtt.relayNetKey': ɵ55,
'wireless.protocols.mqtt.requestTopic': ɵ56,
'wireless.protocols.mqtt.responseTopic': ɵ57,
'wireless.protocols.mqtt.username': ɵ58,
'wireless.protocols.nfc.autoLogProfileId': ɵ59,
'wireless.protocols.nfc.connectionPriority': ɵ60,
'wireless.protocols.wifi.countryCode': ɵ61,
'wireless.protocols.wifi.dnsIp': ɵ62,
'wireless.protocols.wifi.gatewayIp': ɵ63,
'wireless.protocols.wifi.ip': ɵ64,
'wireless.protocols.wifi.key': ɵ65,
'wireless.protocols.wifi.keyVisibility': ɵ66,
'wireless.protocols.wifi.mask': ɵ67,
'wireless.protocols.wifi.mode': ɵ68,
'wireless.protocols.wifi.networkMode': ɵ69,
'wireless.protocols.wifi.protocol': ɵ70,
'wireless.protocols.wifi.ssid': ɵ71,
'wireless.protocols.wifi.ssidVisibility': ɵ72,
'wireless.protocols.wifi.txPower': ɵ73,
};
var ɵ0 = function (context) {
var _a, _b, _c, _d, _e;
var protocolType = ((_b = (_a = context.config) === null || _a === void 0 ? void 0 : _a.target) === null || _b === void 0 ? void 0 : _b.type) === 'MCU'
? (_e = (_d = (_c = context.config) === null || _c === void 0 ? void 0 : _c.target) === null || _d === void 0 ? void 0 : _d.protocol) === null || _e === void 0 ? void 0 : _e.type
: 'MODBUS';
switch (protocolType) {
case undefined:
case 'NONE':
case 'SWD':
// case 'JTAG':
case 'GPIO':
case 'CUSTOM':
// Nothing more to read
return undefined;
case 'S3P':
return context.service.target.getS3PConfigurationCall();
case 'MODBUS':
case 'SERIAL':
return context.service.target.getSerialModbusConfigurationCall();
case 'CAN':
if (context.firmwareVersion) {
if (!isTapFirmwareVersionGreaterThanOrEqual(context.firmwareVersion, '2.6')) {
return new ConfigKeyNotSupportedByFirmwareVersion('target.protocol.config', context.firmwareVersion, {
minApiVersion: '2.6',
maxApiVersion: undefined,
});
}
}
return context.service.target.getCanConfigurationCall();
default:
return exports.TapConfiguratorError.invalidConfiguration("Target protocol \"" + protocolType + "\" is not supported by this version of the configurator");
}
};
var READ_CONFIGURATOR_CUSTOM_CONFIG = {
'target.protocol.config': ɵ0,
};
var READ_CONFIGURATOR_CONFIG = Object.assign(Object.assign({}, READ_CONFIGURATOR_CONFIG$1), READ_CONFIGURATOR_CUSTOM_CONFIG);
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
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) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
function stepEvent(observer, step, context, extraData) {
observer.next(Object.assign({ step: step, progress: {
loaded: context.index + 1,
total: context.total,
} }, (extraData || {})));
}
/**
* Configure tap from a configuration file schema
*
*/
exports.TapConfiguratorReader = /** @class */ (function () {
function TapConfiguratorReader(calls) {
if (calls === void 0) { calls = READ_CONFIGURATOR_CONFIG; }
this.calls = calls;
}
TapConfiguratorReader.prototype.createReadOperations = function (tap) {
var configureContext = {
tap: tap,
};
var operations = [];
var outputConfig = {};
this.addConfigurCalls(configureContext, this.calls, operations, outputConfig, tap);
return taskManager.StepOperations.sequential(operations);
};
TapConfiguratorReader.prototype.addConfigurCalls = function (configureContext, calls, operations, outputConfig, tap) {
var _this = this;
var index = 0;
var _loop_1 = function (key) {
var context = {
firmwareVersion: '9999.9999',
service: tap.service,
param: undefined,
config: outputConfig,
};
var configKey = key;
var factoryFct = calls[configKey];
if (!factoryFct) {
index++;
return "continue";
}
var callOrErrorOrUndefined = factoryFct(context);
if (callOrErrorOrUndefined) {
operations.push(function (observer, context) { return __awaiter(_this, void 0, void 0, function () {
var _a, _b, error_1;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
if (!(callOrErrorOrUndefined instanceof Error)) return [3 /*break*/, 1];
stepEvent(observer, TapConfiguratorReader.Step.readKeyError, context, {
configKey: configKey,
error: callOrErrorOrUndefined,
// call: callOrError
});
return [3 /*break*/, 4];
case 1:
_c.trys.push([1, 3, , 4]);
_a = outputConfig;
_b = configKey;
return [4 /*yield*/, configureContext.tap.lwm2m.execute(callOrErrorOrUndefined)];
case 2:
_a[_b] = (_c.sent()).body();
stepEvent(observer, TapConfiguratorReader.Step.readKeySuccess, context, {
configKey: configKey,
value: outputConfig[configKey],
call: callOrErrorOrUndefined,
});
return [3 /*break*/, 4];
case 3:
error_1 = _c.sent();
stepEvent(observer, TapConfiguratorReader.Step.readKeyError, context, {
configKey: configKey,
call: callOrErrorOrUndefined,
error: error_1,
});
return [3 /*break*/, 4];
case 4: return [2 /*return*/];
}
});
}); });
}
index++;
};
for (var key in calls) {
_loop_1(key);
}
operations.push(function (observer, context) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
stepEvent(observer, TapConfiguratorReader.Step.done, context, {
config: outputConfig,
});
return [2 /*return*/];
});
}); });
};
TapConfiguratorReader.prototype.sleep = function (delayMs) {
return utility.sleep(delayMs);
};
return TapConfiguratorReader;
}());
(function (TapConfiguratorReader) {
var Step;
(function (Step) {
Step["readKeySuccess"] = "TapConfiguratorReaderreadKeySuccess";
Step["readKeyError"] = "TapConfiguratorReaderReadKeyError";
Step["done"] = "TapConfiguratorReaderDone";
})(Step = TapConfiguratorReader.Step || (TapConfiguratorReader.Step = {}));
})(exports.TapConfiguratorReader || (exports.TapConfiguratorReader = {}));
/**
* Utility class to build a configuration
*/
var TapConfiguratorConfigBuilder = /** @class */ (function () {
function TapConfiguratorConfigBuilder(_schema) {
this._schema = _schema;
}
Object.defineProperty(TapConfiguratorConfigBuilder.prototype, "configData", {
get: function () {
if (!this._schema.config.data) {
this._schema.config.data = {};
}
return this._schema.config.data;
},
enumerable: false,
configurable: true
});
Object.defineProperty(TapConfiguratorConfigBuilder.prototype, "profiles", {
get: function () {
if (!this.configData.profiles) {
this.configData.profiles = [];
}
return this.configData.profiles;
},
enumerable: false,
configurable: true
});
Object.defineProperty(TapConfiguratorConfigBuilder.prototype, "tapConfig", {
get: function () {
if (!this._schema.config.tap) {
this._schema.config.tap = {};
}
return this._schema.config.tap;
},
enumerable: false,
configurable: true
});
/**
* @deprecated
* TODO move from here as factory method should not polute the class
*/
TapConfiguratorConfigBuilder.default = function () {
return new TapConfiguratorConfigBuilder({
meta: {},
config: {
application: {
name: 'TAP',
},
version: '1.0.0',
tap: {
security: {
disableHardwareFactoryReset: false,
hashPassword: true,
disableLoginWithUID: false,
disableResourceFactoryReset: false,
scramActivated: false,
},
scram: {
hashIteration: 5000,
},
},
data: {
profiles: SPECIAL_USERS,
},
},
});
};
/**
* Set application name
* @param appName
*/
TapConfiguratorConfigBuilder.prototype.appName = function (appName) {
if (!this._schema.config.application) {
this._schema.config.application = {};
}
this._schema.config.application.name = appName;
return this;
};
/**
* Edit user identified by username
* If user does not it will be created with default values
* @param username
* @param editor
*/
TapConfiguratorConfigBuilder.prototype.user = function (username, editor) {
var userDataIndex = this.profiles.findIndex(function (p) { return p.username === username; });
var userData = userDataIndex >= 0 ? this.profiles[userDataIndex] : undefined;
if (!userData) {
// TODO check SpecialProfileConfig
userData = {
username: username,
lifeTime: 300,
password: username,
};
}
userData = editor(userData);
this.profiles[userDataIndex] = userData;
return this;
};
/**
* Enable/disable scram
* @param enabled true to enable scram
*/
TapConfiguratorConfigBuilder.prototype.scram = function (enabled) {
// TODO hash iteration count ?
if (!this.tapConfig.security) {
this.tapConfig.security = {
scramActivated: false,
disableHardwareFactoryReset: false,
hashPassword: true,
disableResourceFactoryReset: false,
disableLoginWithUID: false,
};
}
else {
this.tapConfig.security.scramActivated = enabled;
if (enabled) {
this.tapConfig.security.hashPassword = true;
}
}
return this;
};
TapConfiguratorConfigBuilder.prototype.build = function () {
return this._schema;
};
return TapConfiguratorConfigBuilder;
}());
/**
* Generated bundle index. Do not edit.
*/
exports.ADMIN_USER = ADMIN_USER;
exports.ANONYMOUS_USER = ANONYMOUS_USER;
exports.READ_CONFIGURATOR_CONFIG = READ_CONFIGURATOR_CONFIG;
exports.SERIAL_SERVER_USER = SERIAL_SERVER_USER;
exports.SPECIAL_USERS = SPECIAL_USERS;
exports.SUPERVISOR_USER = SUPERVISOR_USER;
exports.TapConfiguratorConfigBuilder = TapConfiguratorConfigBuilder;
exports.WRITE_CONFIGURATOR_CONFIG = WRITE_CONFIGURATOR_CONFIG;
exports.getProfileIdFromConfig = getProfileIdFromConfig;
exports.isSpecialUser = isSpecialProfileUsername;
exports.isTapFirmwareVersionGreaterThanOrEqual = isTapFirmwareVersionGreaterThanOrEqual;
exports.isTapFirmwareVersionLessThanOrEqual = isTapFirmwareVersionLessThanOrEqual;
exports.parseTapConfiguratorConfig = parseTapConfiguratorConfig;
exports.tapConfigToServiceCalls = tapConfigToServiceCalls;
exports.validateTapConfiguratorConfig = validateTapConfiguratorConfig;
exports["ɵa"] = compareVersionNumbers;
Object.defineProperty(exports, '__esModule', { value: true });
}));
//# sourceMappingURL=iotize-tap-configurator.umd.js.map