@@ -21449,7 +21449,9 @@ class Collector {
2144921449 this.name = streamData.name;
2145021450 this.appManaging = appManaging;
2145121451 this.#streamData = streamData;
21452- this.request = new CollectorRequest({});
21452+ this.request = new CollectorRequest({
21453+ id: this.id
21454+ });
2145321455 this.#cache = {
2145421456 initialized: false,
2145521457 invites: {},
@@ -22271,17 +22273,10 @@ __webpack_require__.r(__webpack_exports__);
2227122273/* harmony export */ __webpack_require__.d(__webpack_exports__, {
2227222274/* harmony export */ CollectorRequest: () => (/* binding */ CollectorRequest)
2227322275/* harmony export */ });
22274- /**
22275- * Each Collector has one Request
22276- * Which contains
22277- * - the name of the requester
22278- * - a title
22279- * - an id
22280- * - a description
22281- * - a consent message
22282- * - a set of permission requests
22283- * - a version
22284- */
22276+ /* harmony import */ var _errors_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../errors.js */ "./src/errors.js");
22277+ /* harmony import */ var _errors_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_errors_js__WEBPACK_IMPORTED_MODULE_0__);
22278+ /* harmony import */ var _localizeText_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../localizeText.js */ "./src/localizeText.js");
22279+ /* harmony import */ var _localizeText_js__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_localizeText_js__WEBPACK_IMPORTED_MODULE_1__);
2228522280var __classPrivateFieldSet = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2228622281 if (kind === "m") throw new TypeError("Private method is not writable");
2228722282 if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
@@ -22293,12 +22288,34 @@ var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) ||
2229322288 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");
2229422289 return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
2229522290};
22296- var _CollectorRequest_content;
22291+ var _CollectorRequest_version, _CollectorRequest_title, _CollectorRequest_description, _CollectorRequest_consent, _CollectorRequest_requester, _CollectorRequest_app, _CollectorRequest_permissions, _CollectorRequest_extraContent;
22292+
22293+
22294+ /**
22295+ * Each Collector has one Request
22296+ * Which contains
22297+ * - the name of the requester
22298+ * - a title
22299+ * - a description
22300+ * - a consent message
22301+ * - a set of permission requests
22302+ * - a version
22303+ */
2229722304class CollectorRequest {
2229822305 constructor(content) {
22299- _CollectorRequest_content.set(this, void 0);
22300- this.id = content.id || null;
22301- __classPrivateFieldSet(this, _CollectorRequest_content, content, "f");
22306+ _CollectorRequest_version.set(this, void 0);
22307+ _CollectorRequest_title.set(this, void 0);
22308+ _CollectorRequest_description.set(this, void 0);
22309+ _CollectorRequest_consent.set(this, void 0);
22310+ _CollectorRequest_requester.set(this, void 0);
22311+ _CollectorRequest_app.set(this, void 0);
22312+ _CollectorRequest_permissions.set(this, void 0);
22313+ _CollectorRequest_extraContent.set(this, void 0);
22314+ __classPrivateFieldSet(this, _CollectorRequest_version, 0, "f");
22315+ __classPrivateFieldSet(this, _CollectorRequest_requester, { name: null }, "f");
22316+ __classPrivateFieldSet(this, _CollectorRequest_app, { id: null, url: null, data: {} }, "f");
22317+ __classPrivateFieldSet(this, _CollectorRequest_permissions, [], "f");
22318+ this.setContent(content);
2230222319 }
2230322320 /**
2230422321 * Loadfrom status event
@@ -22307,26 +22324,107 @@ class CollectorRequest {
2230722324 */
2230822325 loadFromStatusEvent(statusEvent) {
2230922326 // content.data is deprecated it was used in a previous version, should be removed
22310- __classPrivateFieldSet(this, _CollectorRequest_content, statusEvent.content.request || statusEvent.content.data, "f") ;
22327+ let potentialContent = statusEvent.content.request || statusEvent.content.data;
2231122328 // for some reason to be investigated sometime the data is in requestContent
22312- if (__classPrivateFieldGet(this, _CollectorRequest_content, "f").requestContent)
22313- __classPrivateFieldSet(this, _CollectorRequest_content, __classPrivateFieldGet(this, _CollectorRequest_content, "f").requestContent, "f");
22329+ if (potentialContent.requestContent)
22330+ potentialContent = potentialContent.requestContent;
22331+ this.setContent(potentialContent);
2231422332 }
2231522333 /**
2231622334 * Temp content
2231722335 * @param content
2231822336 */
2231922337 setContent(content) {
22320- __classPrivateFieldSet(this, _CollectorRequest_content, content, "f");
22338+ const futureContent = structuredClone(content);
22339+ // validate content
22340+ if (futureContent.version) {
22341+ const numV = Number.parseInt(futureContent.version);
22342+ if (numV !== __classPrivateFieldGet(this, _CollectorRequest_version, "f"))
22343+ throw new _errors_js__WEBPACK_IMPORTED_MODULE_0__.HDSLibError(`Invalid CollectorRequest content version: ${futureContent.version}`);
22344+ delete futureContent.version;
22345+ }
22346+ for (const key of ['title', 'consent', 'description']) {
22347+ if (futureContent[key] != null) {
22348+ this[key] = futureContent[key];
22349+ }
22350+ delete futureContent[key];
22351+ }
22352+ if (futureContent.requester) {
22353+ if (futureContent.requester.name != null) {
22354+ this.requesterName = futureContent.requester.name;
22355+ }
22356+ delete futureContent.requester;
22357+ }
22358+ if (futureContent.app) {
22359+ if (futureContent.app.id != null) {
22360+ this.appId = futureContent.app.id;
22361+ }
22362+ if (futureContent.app.url != null) {
22363+ this.appUrl = futureContent.app.url;
22364+ }
22365+ if (futureContent.app.data != null) {
22366+ this.appCustomData = futureContent.app.data;
22367+ }
22368+ delete futureContent.app;
22369+ }
22370+ if (futureContent.permissions) {
22371+ __classPrivateFieldSet(this, _CollectorRequest_permissions, [], "f"); // reset permissions
22372+ futureContent.permissions.forEach((p) => {
22373+ this.addPermissions(p.streamId, p.defaultName, p.level);
22374+ });
22375+ delete futureContent.permissions;
22376+ }
22377+ __classPrivateFieldSet(this, _CollectorRequest_extraContent, futureContent, "f");
22378+ }
22379+ // ------------- getter and setters ------------ //
22380+ get version() { return __classPrivateFieldGet(this, _CollectorRequest_version, "f"); }
22381+ set title(title) { __classPrivateFieldSet(this, _CollectorRequest_title, (0,_localizeText_js__WEBPACK_IMPORTED_MODULE_1__.validateLocalizableText)('title', title), "f"); }
22382+ get title() { return __classPrivateFieldGet(this, _CollectorRequest_title, "f"); }
22383+ set consent(consent) { __classPrivateFieldSet(this, _CollectorRequest_consent, (0,_localizeText_js__WEBPACK_IMPORTED_MODULE_1__.validateLocalizableText)('consent', consent), "f"); }
22384+ get consent() { return __classPrivateFieldGet(this, _CollectorRequest_consent, "f"); }
22385+ set description(description) { __classPrivateFieldSet(this, _CollectorRequest_description, (0,_localizeText_js__WEBPACK_IMPORTED_MODULE_1__.validateLocalizableText)('description', description), "f"); }
22386+ get description() { return __classPrivateFieldGet(this, _CollectorRequest_description, "f"); }
22387+ set requesterName(name) { __classPrivateFieldGet(this, _CollectorRequest_requester, "f").name = validateString('requester:name', name); }
22388+ get requesterName() { return __classPrivateFieldGet(this, _CollectorRequest_requester, "f").name; }
22389+ set appId(id) { __classPrivateFieldGet(this, _CollectorRequest_app, "f").id = validateString('app:id', id); }
22390+ get appId() { return __classPrivateFieldGet(this, _CollectorRequest_app, "f").id; }
22391+ set appUrl(url) { __classPrivateFieldGet(this, _CollectorRequest_app, "f").url = validateString('app:url', url); }
22392+ get appUrl() { return __classPrivateFieldGet(this, _CollectorRequest_app, "f").url; }
22393+ set appCustomData(data) { __classPrivateFieldGet(this, _CollectorRequest_app, "f").data = data; }
22394+ get appCustomData() { return __classPrivateFieldGet(this, _CollectorRequest_app, "f").data; }
22395+ get permissions() { return __classPrivateFieldGet(this, _CollectorRequest_permissions, "f"); }
22396+ // ---------- permissions ---------- //
22397+ addPermissions(streamId, defaultName, level) {
22398+ __classPrivateFieldGet(this, _CollectorRequest_permissions, "f").push({ streamId, defaultName, level });
2232122399 }
2232222400 /**
22323- * Return
22401+ * Return Content to comply with initial implementation as an object
2232422402 */
2232522403 get content() {
22326- return __classPrivateFieldGet(this, _CollectorRequest_content, "f");
22404+ const content = {
22405+ title: this.title,
22406+ consent: this.consent,
22407+ description: this.description,
22408+ requester: {
22409+ name: this.requesterName
22410+ },
22411+ permissions: this.permissions,
22412+ app: {
22413+ id: this.appId,
22414+ url: this.appUrl,
22415+ data: this.appCustomData
22416+ }
22417+ };
22418+ Object.assign(content, __classPrivateFieldGet(this, _CollectorRequest_extraContent, "f"));
22419+ return content;
2232722420 }
2232822421}
22329- _CollectorRequest_content = new WeakMap();
22422+ _CollectorRequest_version = new WeakMap(), _CollectorRequest_title = new WeakMap(), _CollectorRequest_description = new WeakMap(), _CollectorRequest_consent = new WeakMap(), _CollectorRequest_requester = new WeakMap(), _CollectorRequest_app = new WeakMap(), _CollectorRequest_permissions = new WeakMap(), _CollectorRequest_extraContent = new WeakMap();
22423+ function validateString(key, totest) {
22424+ if (totest == null || typeof totest !== 'string')
22425+ throw new _errors_js__WEBPACK_IMPORTED_MODULE_0__.HDSLibError(`Invalid ${key} value: ${totest}`, { [key]: totest });
22426+ return totest;
22427+ }
2233022428
2233122429
2233222430/***/ }),
@@ -22428,7 +22526,8 @@ module.exports = {
2242822526 setPreferredLocales,
2242922527 getPreferredLocales,
2243022528 getSupportedLocales,
22431- resetPreferredLocales
22529+ resetPreferredLocales,
22530+ validateLocalizableText
2243222531};
2243322532
2243422533const supportedLocales = ['en', 'fr', 'es'];
@@ -22488,6 +22587,20 @@ function setPreferredLocales (arrayOfLocals) {
2248822587
2248922588 preferredLocales = [...new Set([...arrayOfLocals, ...preferredLocales])];
2249022589}
22590+ /**
22591+ * throw errors if an item is not of type localizableText
22592+ * @param {string} key
22593+ * @param {*} toTest
22594+ * @returns {import('../types/localizeText').localizableText}
22595+ */
22596+ function validateLocalizableText (key, toTest) {
22597+ if (toTest.en == null || typeof toTest.en !== 'string') throw new HDSLibError(`Missing or invalid localizable text for ${key}`, { [key]: toTest });
22598+ for (const optionalLang of supportedLocales) {
22599+ if (optionalLang === 'en') continue;
22600+ if (toTest[optionalLang] != null && typeof toTest[optionalLang] !== 'string') throw new HDSLibError(`Missing or invalid localizable text for ${key} languagecode: ${optionalLang}`, { [key]: toTest, languageCode: optionalLang });
22601+ }
22602+ return toTest;
22603+ }
2249122604
2249222605
2249322606/***/ }),
@@ -24448,6 +24561,18 @@ describe('[TKSX] toolKit Stream Auto Create', () => {
2444824561/******/ }
2444924562/******/
2445024563/************************************************************************/
24564+ /******/ /* webpack/runtime/compat get default export */
24565+ /******/ (() => {
24566+ /******/ // getDefaultExport function for compatibility with non-harmony modules
24567+ /******/ __webpack_require__.n = (module) => {
24568+ /******/ var getter = module && module.__esModule ?
24569+ /******/ () => (module['default']) :
24570+ /******/ () => (module);
24571+ /******/ __webpack_require__.d(getter, { a: getter });
24572+ /******/ return getter;
24573+ /******/ };
24574+ /******/ })();
24575+ /******/
2445124576/******/ /* webpack/runtime/define property getters */
2445224577/******/ (() => {
2445324578/******/ // define getter functions for harmony exports
0 commit comments