@edifice.io/client
Version:
1,526 lines • 147 kB
JavaScript
var T = Object.defineProperty;
var P = (u, e, t) => e in u ? T(u, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : u[e] = t;
var n = (u, e, t) => P(u, typeof e != "symbol" ? e + "" : e, t);
import axios from "axios";
import { MimeTypeUtils } from "@edifice.io/utilities";
const ERROR_CODE = {
SUCCESS: "0000",
UNKNOWN: "0010",
NOT_INITIALIZED: "0020",
NOT_SUPPORTED: "0030",
APP_NOT_FOUND: "0040",
AGENT_NOT_FOUND: "0050",
TRANSPORT_ERROR: "0060",
TIME_OUT: "0070",
MALFORMED_DATA: "0080",
NOT_LOGGED_IN: "0090"
}, APP$4 = {
ADMIN: "admin",
ARCHIVE: "archive",
AUTH: "auth",
CAS: "cas",
COMMUNICATION: "communication",
CONVERSATION: "conversation",
DIRECTORY: "directory",
// FIXME userbook OR directory : the choice may impact some configurations, @see IXitiTrackingParams.NOM_PAGE for example
USERBOOK: "userbook",
INFRA: "infra",
PORTAL: "portal",
TIMELINE: "timeline",
WORKSPACE: "workspace",
// -- a few others commonly used apps
EXPLORER: "explorer",
HOMEWORKS: "homeworks",
VIDEO: "video",
MINDMAP: "mindmap",
SCRAPBOOK: "scrapbook",
COLLABORATIVEWALL: "collaborativewall",
WIKI: "wiki",
TIMELINEGENERATOR: "timelinegenerator",
COLLABORATIVEEDITOR: "collaborativeeditor"
// TODO compléter/trier les apps suivantes
/*
"competences"
"cahier-textes"
"poll"
"rack"
"rbs"
"searchengine"
"sharebigfiles"
"schoolbook"
"archive"
"admin"
"cahier-de-texte"
"wiki"
"cns"
"conversation"
"paths"
"parcours"
"notebook"
"account"
"support"
"workspace"
"admin-portal"
"stats"
"userbook" // FIXME userbook OR directory : the choice may impact some configurations, @see IXitiTrackingParams.NOM_PAGE for example
"directory" // FIXME Keep in mind that ode-ts-client MUST not access the locationPath of the window !
"mindmap"
"timelinegenerator"
"actualites"
"pad"
"collaborativeeditor"
"settings-class"
"library"
"visioconf"
"Web-conference"
"notes"
"attendance"
"calendar"
"canal-numerique"
"collaborative-wall"
"statistics"
"polls"
"community"
"forum"
"pages"
"website"
"parametrage"
"kne"
"sacoche"
*/
}, USER_PREFS = {
APPS: "apps",
WIDGETS: "widgets",
LANGUAGE: "language",
AUTH_CONNECTOR_ACCESSED: "authenticatedConnectorsAccessed",
CURSUS: "cursus",
INFOTIP: "infotip",
RGPD_COOKIES: "rgpdCookies"
// TODO compléter
}, b = class b {
constructor(e) {
n(this, "name");
n(this, "listeners", /* @__PURE__ */ new Set());
this.name = e;
}
/**
* Get a channel by name (create it if it doesn't exist).
* @param name of the channel
* @returns the channel instance
*/
static getChannel(e) {
let t = b.channels.get(e);
return t || (t = new b(e), b.channels.set(e, t)), t;
}
/**
* Add a listener and return a revocation function to remove it.
*/
listen(e) {
return this.listeners.add(e), () => {
this.listeners.delete(e);
};
}
/**
* Publish a message to all listeners.
*/
publish(e) {
for (const t of Array.from(this.listeners))
try {
t(e);
} catch (s) {
console.error("[SimpleChannel] publish failed", s);
}
}
/**
* Close this channel: remove listeners and unregister from global map.
*/
close() {
this.listeners.clear(), b.channels.delete(this.name);
}
};
n(b, "channels", /* @__PURE__ */ new Map());
let SimpleChannel = b;
class Subscription {
constructor(e, t) {
n(this, "revoke");
this._channel = e, this.revoke = this.setReceiver((s) => t == null ? void 0 : t(s));
}
setReceiver(e) {
if (!this._channel) return () => {
};
const t = this._channel.listen(e);
return () => {
t(), this._channel = void 0;
};
}
}
class Subject {
constructor() {
/* We maintain channels for sending messages.
* Receiving channels are instantiated per subscription.
*/
n(this, "publishChannels", /* @__PURE__ */ new Map());
}
getChannelName(e) {
return "Subject:" + e;
}
getPublishChannel(e) {
const t = this.getChannelName(e);
let s = this.publishChannels.get(t);
return s || (s = this.newChannel(e), this.publishChannels.set(t, s)), s;
}
newChannel(e) {
const t = this.getChannelName(e);
return SimpleChannel.getChannel(t);
}
publish(e, t) {
typeof e == "string" && this.getPublishChannel(e).publish(t);
}
subscribe(e, t) {
if (typeof e == "string") {
const s = this.newChannel(e);
return new Subscription(s, t);
} else
return new Subscription();
}
}
const ASYNC_DATA_NAME = {
SESSION_READY: "sessionReady",
LANG_READY: "langReady",
SKIN_READY: "skinReady",
OVERRIDE_READY: "overrideReady",
APPCONF_READY: "appConfReady"
};
class Promisified {
constructor() {
//-------------------------------------
n(this, "_resolution");
n(this, "_rejection");
n(this, "_promise", new Promise((e, t) => {
this._resolution = e, this._rejection = t;
}));
}
get promise() {
return this._promise;
}
resolve(e) {
this._resolution && this._resolution(e);
}
reject(e) {
this._rejection && this._rejection(e);
}
}
class NotifyFramework {
constructor() {
//-------------------------------------
n(this, "promises", {});
n(this, "subject", new Subject());
}
asyncData(e) {
return typeof this.promises[e] > "u" && (this.promises[e] = new Promisified()), this.promises[e];
}
onSessionReady() {
return this.asyncData(ASYNC_DATA_NAME.SESSION_READY);
}
onLangReady() {
return this.asyncData(ASYNC_DATA_NAME.LANG_READY);
}
onSkinReady() {
return this.asyncData(ASYNC_DATA_NAME.SKIN_READY);
}
onOverridesReady() {
return this.asyncData(ASYNC_DATA_NAME.OVERRIDE_READY);
}
onAppConfReady() {
return this.asyncData(ASYNC_DATA_NAME.APPCONF_READY);
}
promisify() {
return new Promisified();
}
events() {
return this.subject;
}
}
const notify = new NotifyFramework(), loadedScripts$1 = {};
class Http {
constructor(e) {
// Axios automatically manages the XSRF-TOKEN cookie and the X-XSRF-TOKEN HTTP header.
n(this, "axios");
n(this, "_latestResponse");
this.axios = axios.create(e);
}
setCdn(e) {
e && XMLHttpRequest && !XMLHttpRequest.prototype.cdnUrl && (XMLHttpRequest.prototype.cdnUrl = e, XMLHttpRequest.prototype.baseOpen = XMLHttpRequest.prototype.open, XMLHttpRequest.prototype.open = function() {
const t = arguments[1];
return t.startsWith("/infra/public") && (arguments[1] = e + t), /^\/([^\/]*)\/public/.test(t) && (arguments[1] = e + t), t.startsWith("/assets") && (arguments[1] = e + t), t == "/conf/public" && (arguments[1] = t), t.startsWith("http") && (arguments[1] = t), this.baseOpen.apply(this, arguments);
});
}
// private toAxiosConfig(params?: IHttpParams): AxiosRequestConfig {
toAxiosConfig(e) {
if (e) {
const t = Object.assign({}, this.axios.defaults);
return e.headers && (t.headers && (t.headers = Object.assign({}, this.axios.defaults.headers)), Object.assign(t.headers, e.headers)), e.responseType && (t.responseType = e.responseType), e.queryParams && (t.params = Object.assign({}, e.queryParams)), t;
} else
return this.axios.defaults;
}
toCdnUrl(e) {
const t = ConfigurationFrameworkFactory.instance().Platform.cdnDomain;
if ((t == null ? void 0 : t.length) > 0 && e !== "/conf/public") {
const s = "" + e;
(s.startsWith("/infra/public") || s.startsWith("/assets") || /^\/([^\/]*)\/public/.test(s)) && (e = t + s);
}
return e;
}
mapAxiosError(e, t) {
return e.response ? this._latestResponse = e.response : e.request ? this._latestResponse = {
status: 408,
statusText: ERROR_CODE.TIME_OUT
} : this._latestResponse = {
status: 500,
statusText: ERROR_CODE.UNKNOWN
}, !t || t.disableNotifications, this._latestResponse;
}
mapAxiosResponse(e, t) {
return this._latestResponse = e, e.data;
}
get latestResponse() {
return this._latestResponse;
}
isResponseError() {
return this.latestResponse.status < 200 || this.latestResponse.status >= 300;
}
get(e, t) {
return this.axios.get(this.toCdnUrl(e), this.toAxiosConfig(t)).then((s) => this.mapAxiosResponse(s, t)).catch((s) => this.mapAxiosError(s, t));
}
post(e, t, s) {
return this.axios.post(e, t, this.toAxiosConfig(s)).then((r) => this.mapAxiosResponse(r, s)).catch((r) => this.mapAxiosError(r, s));
}
postFile(e, t, s) {
const r = this.toAxiosConfig(s);
return r.headers && r.headers["Content-Type"] && delete r.headers["Content-Type"], this.axios.post(e, t, r).then((i) => this.mapAxiosResponse(i, s)).catch((i) => this.mapAxiosError(i, s));
}
postJson(e, t, s) {
const r = this.toAxiosConfig();
return r.headers && (r.headers["Content-Type"] = "application/json"), this.axios.post(e, t, this.toAxiosConfig(s)).then((i) => this.mapAxiosResponse(i, s)).catch((i) => this.mapAxiosError(i, s));
}
put(e, t, s) {
return this.axios.put(e, t, this.toAxiosConfig(s)).then((r) => this.mapAxiosResponse(r, s)).catch((r) => this.mapAxiosError(r, s));
}
/*
putFile(url: string, data:FormData, opt?:any) {
//TODO
return this.axios.putFile(url, data, opt).then( r => this.mapAxiosResponse(r,params));
}
*/
putJson(e, t, s) {
const r = this.toAxiosConfig(s);
return r.headers && (r.headers["Content-Type"] = "application/json"), this.axios.put(e, t, r).then((i) => this.mapAxiosResponse(i, s)).catch((i) => this.mapAxiosError(i, s));
}
delete(e, t) {
return this.axios.delete(e, this.toAxiosConfig(t)).then((s) => this.mapAxiosResponse(s, t)).catch((s) => this.mapAxiosError(s, t));
}
deleteJson(e, t) {
return this.axios.delete(e, { data: t }).then((s) => this.mapAxiosResponse(s)).catch((s) => this.mapAxiosError(s));
}
getScript(e, t, s) {
const r = s ?? "exports", i = this.toAxiosConfig(t);
return i.headers && (i.headers.Accept = "application/javascript"), this.axios.get(this.toCdnUrl(e), i).then((o) => this.mapAxiosResponse(o, t)).then((o) => {
try {
const a = `"use strict";var ${r.split(".")[0]}={};${o};return ${r};`;
return Function(a)();
} catch {
return o;
}
}).catch((o) => {
throw this.mapAxiosError(o, t), o;
});
}
loadScript(e, t) {
return loadedScripts$1[e] ? Promise.resolve() : this.getScript(e, t).then((s) => {
loadedScripts$1[e] = !0;
});
}
}
class TransportFramework {
constructor() {
n(this, "_http", new Http());
}
get http() {
return this._http;
}
newHttpInstance(e) {
return new Http(e);
}
}
const transport = new TransportFramework();
class ConfigurationFrameworkFactory {
//-------------------------------------
static instance() {
return configure;
}
}
const http$2 = transport.http;
class Session {
constructor() {
n(this, "_me", null);
n(this, "_currentLanguage", "");
n(this, "_notLoggedIn", !0);
n(this, "_description");
n(this, "_profile");
}
get currentLanguage() {
return this._currentLanguage;
}
get notLoggedIn() {
return this._notLoggedIn;
}
get description() {
return this._description;
}
get avatarUrl() {
let e = this.description.photo;
return (!e || e === "no-avatar.jpg" || e === "no-avatar.svg") && (e = ConfigurationFrameworkFactory.instance().Platform.theme.basePath + "/img/illustrations/no-avatar.svg"), e;
}
get user() {
return this._me;
}
get currentApp() {
return configure.Platform.apps.currentApp;
}
async initialize() {
return http$2.get("/auth/oauth2/userinfo").then((e) => {
if (http$2.isResponseError() || typeof e == "string")
throw ERROR_CODE.NOT_LOGGED_IN;
return this.setCurrentModel(e), this._notLoggedIn ? this.loadDefaultLanguage() : this.loadUserLanguage();
}).then((e) => (this.setCurrentLanguage(e), this.loadDescription())).then(() => this.getUserProfile()).then(() => {
notify.onSessionReady().resolve(this._me);
}).catch((e) => {
if (e === ERROR_CODE.NOT_LOGGED_IN)
return Promise.resolve();
notify.onSessionReady().reject(e);
});
}
setCurrentModel(e) {
this._me = e, this._notLoggedIn = !(e && e.sessionMetadata && e.sessionMetadata.userId);
}
////////////////////////////////////////////////////////// Rights management
hasWorkflow(e) {
var t;
return e === void 0 || ((t = this._me) == null ? void 0 : t.authorizedActions.findIndex((s) => s.name === e)) !== -1;
}
hasRight(e, t) {
if (t === "owner")
return e.owner && e.owner.userId === this._me.userId;
const s = t.right || t, i = e.shared.filter((a) => (this._me.groupsIds || []).indexOf(a.groupId) !== -1 || a.userId === this._me.userId).find((a) => a[s] || a.manager) !== void 0, o = t.workflow ? this.hasWorkflow(t.workflow) : !0;
return i && o;
}
////////////////////////////////////////////////////////// Storage management
get latestQuotaAndUsage() {
return http$2.get(`/workspace/quota/user/${this._me.userId}`).then((e) => (this._description && (this._description.quota = e.quota, this._description.storage = e.storage), e)).catch(() => ({ quota: 0, storage: 0 }));
}
////////////////////////////////////////////////////////// Language management
setCurrentLanguage(e) {
this._currentLanguage = e, notify.onLangReady().resolve(e);
}
loadDefaultLanguage() {
return http$2.get("/locale").then((e) => e.locale).catch(() => this._currentLanguage);
}
////////////////////////////////////////////////////////// Description management
loadDescription() {
return Promise.all([
// FIXME The full user's description should be obtainable from a single endpoint in the backend.
http$2.get("/userbook/api/person", {
requestName: "refreshAvatar"
}),
http$2.get("/directory/userbook/" + this._me.userId)
]).then((e) => (e[0].status === "ok" && e[0].result && e[0].result.length > 0 ? this._description = e[0].result[0] : this._description = {}, this._description.type && !this._description.profiles && (this._description.profiles = this._description.type), Object.assign(this._description, e[1]), this._description));
}
get profile() {
return this._profile;
}
getUserProfile() {
return http$2.get("/userbook/api/person").then((e) => e.result).then((e) => this._profile = e[0].type);
}
loadUserLanguage() {
return http$2.get("/userbook/preference/language").then((e) => {
try {
return JSON.parse(e.preference)["default-domain"];
} catch {
return this.loadDefaultLanguage();
}
}).catch(() => this.loadDefaultLanguage());
}
////////////////////////////////////////////////////////// Email management
getEmailValidationInfos() {
return http$2.get("/directory/user/mailstate");
}
checkEmail(e) {
return http$2.put("/directory/user/mailstate", { email: e });
}
tryEmailValidation(e) {
return http$2.post("/directory/user/mailstate", {
key: e
});
}
////////////////////////////////////////////////////////// Mobile management
getMobileValidationInfos() {
return http$2.get("/directory/user/mobilestate");
}
checkMobile(e) {
return http$2.put("/directory/user/mobilestate", { mobile: e });
}
tryMobileValidation(e) {
return http$2.post("/directory/user/mobilestate", {
key: e
});
}
////////////////////////////////////////////////////////// MFA management
getMfaInfos() {
return http$2.get("/auth/user/mfa/code");
}
tryMfaCode(e) {
return http$2.post("/auth/user/mfa/code", { key: e });
}
}
class SessionFramework {
constructor() {
n(this, "session", new Session());
}
initialize() {
return this.session.initialize();
}
login(e, t, s, r) {
const i = new FormData();
return i.append("email", e), i.append("password", t), typeof s < "u" && i.append("rememberMe", "" + s), typeof r < "u" && i.append("secureLocation", "" + r), transport.http.post("/auth/login", i, {
headers: { "content-type": "application/x-www-form-urlencoded" }
}).finally(() => {
switch (transport.http.latestResponse.status) {
case 200:
throw ERROR_CODE.MALFORMED_DATA;
}
});
}
logout() {
return transport.http.get("/auth/logout").finally(() => {
});
}
}
const session = new SessionFramework();
class Theme {
constructor() {
n(this, "_conf");
n(this, "_loaded");
// legacy (readonly)
n(this, "skinName", "");
n(this, "themeName", "");
n(this, "skin", "raw");
n(this, "themeUrl", "/assets/themes/raw/default/");
n(this, "templateOverrides", {});
n(this, "portalTemplate", "/assets/themes/raw/portal.html");
n(this, "basePath", "");
n(this, "logoutCallback", "");
n(this, "skins", []);
n(this, "is1D", !1);
n(this, "is2D", !1);
n(this, "_onSkinReady", notify.onSkinReady());
n(this, "_onOverrideReady", notify.onOverridesReady());
}
initialize(e) {
return notify.onSessionReady().promise.then(() => this.load(e));
}
get version() {
return configure.Platform.deploymentTag;
}
get cdnDomain() {
return configure.Platform.cdnDomain;
}
async onFullyReady() {
return await this._loaded, this;
}
onSkinReady() {
return this._onSkinReady.promise;
}
onOverrideReady() {
return this._onOverrideReady.promise;
}
async getConf(e) {
return this._conf = this._conf ?? await transport.http.getScript(
"/assets/theme-conf.js",
{ queryParams: { v: e ?? this.version } },
"exports.conf"
), this._conf;
}
load(e) {
return e = e ?? this.version, this._loaded || (this._loaded = (session.session.notLoggedIn ? this.loadDisconnected(e) : this.loadConnected(e)).then(async () => {
var s, r;
const t = await this.listSkins();
this.is1D = ((s = t.find((i) => i.child === this.skin)) == null ? void 0 : s.parent) === "panda", this.is2D = ((r = t.find((i) => i.child === this.skin)) == null ? void 0 : r.parent) === "theme-open-ent";
})), this._loaded;
}
loadDisconnected(e) {
return new Promise((t, s) => {
transport.http.get("/skin", { queryParams: { v: this.version } }).then((r) => {
this.skin = r.skin, this.themeUrl = `${this.cdnDomain}/assets/themes/${r.skin}/skins/default/`, this.basePath = this.themeUrl + "../../", this._onSkinReady.resolve(this), transport.http.get(`/assets/themes/${r.skin}/template/override.json`, {
disableNotifications: !0,
queryParams: { v: e }
}).then((i) => {
this.templateOverrides = i, this._onOverrideReady.resolve(i), t();
}).catch((i) => {
if (transport.http.latestResponse.status === 404)
t();
else
throw i;
});
}).catch((r) => {
this._onSkinReady.reject(r), this._onOverrideReady.reject(r), s();
});
});
}
loadConnected(e) {
return new Promise((t, s) => {
this.loadDefaultTheme(e).then(() => {
this._onSkinReady.resolve(this), transport.http.get(`/assets/themes/${this.skin}/template/override.json`, {
disableNotifications: !0,
queryParams: { v: e }
}).then((r) => {
this.templateOverrides = r, this._onOverrideReady.resolve(r), t();
}).catch((r) => {
if (transport.http.latestResponse.status === 404)
t(), this._onSkinReady.reject(r), this._onOverrideReady.reject(r);
else
throw r;
});
});
});
}
/** Load the user's configured theme. */
async loadDefaultTheme(e) {
return session.session.notLoggedIn ? Promise.reject() : transport.http.get("/theme", { queryParams: { _: e } }).then((t) => {
this.skinName = t.skinName, this.themeName = t.themeName, this.themeUrl = t.skin, this.basePath = `${this.cdnDomain}${this.themeUrl}../../`, this.skin = this.themeUrl.split("/assets/themes/")[1].split("/")[0], this.portalTemplate = `${this.cdnDomain}/assets/themes/${this.skin}/portal.html`, this.logoutCallback = t.logoutCallback;
});
}
listThemes() {
return transport.http.get("/themes");
}
async setDefaultTheme(e) {
await transport.http.get(
"/userbook/api/edit-userbook-info?prop=theme-" + this.skin + "&value=" + e._id
), await this.loadDefaultTheme(this.version);
}
listSkins() {
return this.skins.length > 0 ? Promise.resolve(this.skins) : this.getConf().then((e) => {
const t = e.overriding.find(
(s) => s.child === this.skin
);
return t != null && t.group ? this.skins = this.skins.concat(
e.overriding.filter((s) => s.group === t.group)
) : this.skins = this.skins.concat(e.overriding), this.skins;
});
}
async getHelpPath() {
const t = (await this.listSkins()).find((s) => s.child === this.skin);
return (t == null ? void 0 : t.help) ?? "/help";
}
}
const bundle$1 = {}, promises$1 = {}, defaultDiacriticsRemovalMap$1 = [
{
base: "A",
letters: /[\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F]/g
},
{ base: "AA", letters: /[\uA732]/g },
{ base: "AE", letters: /[\u00C6\u01FC\u01E2]/g },
{ base: "AO", letters: /[\uA734]/g },
{ base: "AU", letters: /[\uA736]/g },
{ base: "AV", letters: /[\uA738\uA73A]/g },
{ base: "AY", letters: /[\uA73C]/g },
{
base: "B",
letters: /[\u0042\u24B7\uFF22\u1E02\u1E04\u1E06\u0243\u0182\u0181]/g
},
{
base: "C",
letters: /[\u0043\u24B8\uFF23\u0106\u0108\u010A\u010C\u00C7\u1E08\u0187\u023B\uA73E]/g
},
{
base: "D",
letters: /[\u0044\u24B9\uFF24\u1E0A\u010E\u1E0C\u1E10\u1E12\u1E0E\u0110\u018B\u018A\u0189\uA779]/g
},
{ base: "DZ", letters: /[\u01F1\u01C4]/g },
{ base: "Dz", letters: /[\u01F2\u01C5]/g },
{
base: "E",
letters: /[\u0045\u24BA\uFF25\u00C8\u00C9\u00CA\u1EC0\u1EBE\u1EC4\u1EC2\u1EBC\u0112\u1E14\u1E16\u0114\u0116\u00CB\u1EBA\u011A\u0204\u0206\u1EB8\u1EC6\u0228\u1E1C\u0118\u1E18\u1E1A\u0190\u018E]/g
},
{ base: "F", letters: /[\u0046\u24BB\uFF26\u1E1E\u0191\uA77B]/g },
{
base: "G",
letters: /[\u0047\u24BC\uFF27\u01F4\u011C\u1E20\u011E\u0120\u01E6\u0122\u01E4\u0193\uA7A0\uA77D\uA77E]/g
},
{
base: "H",
letters: /[\u0048\u24BD\uFF28\u0124\u1E22\u1E26\u021E\u1E24\u1E28\u1E2A\u0126\u2C67\u2C75\uA78D]/g
},
{
base: "I",
letters: /[\u0049\u24BE\uFF29\u00CC\u00CD\u00CE\u0128\u012A\u012C\u0130\u00CF\u1E2E\u1EC8\u01CF\u0208\u020A\u1ECA\u012E\u1E2C\u0197]/g
},
{ base: "J", letters: /[\u004A\u24BF\uFF2A\u0134\u0248]/g },
{
base: "K",
letters: /[\u004B\u24C0\uFF2B\u1E30\u01E8\u1E32\u0136\u1E34\u0198\u2C69\uA740\uA742\uA744\uA7A2]/g
},
{
base: "L",
letters: /[\u004C\u24C1\uFF2C\u013F\u0139\u013D\u1E36\u1E38\u013B\u1E3C\u1E3A\u0141\u023D\u2C62\u2C60\uA748\uA746\uA780]/g
},
{ base: "LJ", letters: /[\u01C7]/g },
{ base: "Lj", letters: /[\u01C8]/g },
{ base: "M", letters: /[\u004D\u24C2\uFF2D\u1E3E\u1E40\u1E42\u2C6E\u019C]/g },
{
base: "N",
letters: /[\u004E\u24C3\uFF2E\u01F8\u0143\u00D1\u1E44\u0147\u1E46\u0145\u1E4A\u1E48\u0220\u019D\uA790\uA7A4]/g
},
{ base: "NJ", letters: /[\u01CA]/g },
{ base: "Nj", letters: /[\u01CB]/g },
{
base: "O",
letters: /[\u004F\u24C4\uFF2F\u00D2\u00D3\u00D4\u1ED2\u1ED0\u1ED6\u1ED4\u00D5\u1E4C\u022C\u1E4E\u014C\u1E50\u1E52\u014E\u022E\u0230\u00D6\u022A\u1ECE\u0150\u01D1\u020C\u020E\u01A0\u1EDC\u1EDA\u1EE0\u1EDE\u1EE2\u1ECC\u1ED8\u01EA\u01EC\u00D8\u01FE\u0186\u019F\uA74A\uA74C]/g
},
{ base: "OI", letters: /[\u01A2]/g },
{ base: "OO", letters: /[\uA74E]/g },
{ base: "OU", letters: /[\u0222]/g },
{
base: "P",
letters: /[\u0050\u24C5\uFF30\u1E54\u1E56\u01A4\u2C63\uA750\uA752\uA754]/g
},
{ base: "Q", letters: /[\u0051\u24C6\uFF31\uA756\uA758\u024A]/g },
{
base: "R",
letters: /[\u0052\u24C7\uFF32\u0154\u1E58\u0158\u0210\u0212\u1E5A\u1E5C\u0156\u1E5E\u024C\u2C64\uA75A\uA7A6\uA782]/g
},
{
base: "S",
letters: /[\u0053\u24C8\uFF33\u1E9E\u015A\u1E64\u015C\u1E60\u0160\u1E66\u1E62\u1E68\u0218\u015E\u2C7E\uA7A8\uA784]/g
},
{
base: "T",
letters: /[\u0054\u24C9\uFF34\u1E6A\u0164\u1E6C\u021A\u0162\u1E70\u1E6E\u0166\u01AC\u01AE\u023E\uA786]/g
},
{ base: "TZ", letters: /[\uA728]/g },
{
base: "U",
letters: /[\u0055\u24CA\uFF35\u00D9\u00DA\u00DB\u0168\u1E78\u016A\u1E7A\u016C\u00DC\u01DB\u01D7\u01D5\u01D9\u1EE6\u016E\u0170\u01D3\u0214\u0216\u01AF\u1EEA\u1EE8\u1EEE\u1EEC\u1EF0\u1EE4\u1E72\u0172\u1E76\u1E74\u0244]/g
},
{ base: "V", letters: /[\u0056\u24CB\uFF36\u1E7C\u1E7E\u01B2\uA75E\u0245]/g },
{ base: "VY", letters: /[\uA760]/g },
{
base: "W",
letters: /[\u0057\u24CC\uFF37\u1E80\u1E82\u0174\u1E86\u1E84\u1E88\u2C72]/g
},
{ base: "X", letters: /[\u0058\u24CD\uFF38\u1E8A\u1E8C]/g },
{
base: "Y",
letters: /[\u0059\u24CE\uFF39\u1EF2\u00DD\u0176\u1EF8\u0232\u1E8E\u0178\u1EF6\u1EF4\u01B3\u024E\u1EFE]/g
},
{
base: "Z",
letters: /[\u005A\u24CF\uFF3A\u0179\u1E90\u017B\u017D\u1E92\u1E94\u01B5\u0224\u2C7F\u2C6B\uA762]/g
},
{
base: "a",
letters: /[\u0061\u24D0\uFF41\u1E9A\u00E0\u00E1\u00E2\u1EA7\u1EA5\u1EAB\u1EA9\u00E3\u0101\u0103\u1EB1\u1EAF\u1EB5\u1EB3\u0227\u01E1\u00E4\u01DF\u1EA3\u00E5\u01FB\u01CE\u0201\u0203\u1EA1\u1EAD\u1EB7\u1E01\u0105\u2C65\u0250]/g
},
{ base: "aa", letters: /[\uA733]/g },
{ base: "ae", letters: /[\u00E6\u01FD\u01E3]/g },
{ base: "ao", letters: /[\uA735]/g },
{ base: "au", letters: /[\uA737]/g },
{ base: "av", letters: /[\uA739\uA73B]/g },
{ base: "ay", letters: /[\uA73D]/g },
{
base: "b",
letters: /[\u0062\u24D1\uFF42\u1E03\u1E05\u1E07\u0180\u0183\u0253]/g
},
{
base: "c",
letters: /[\u0063\u24D2\uFF43\u0107\u0109\u010B\u010D\u00E7\u1E09\u0188\u023C\uA73F\u2184]/g
},
{
base: "d",
letters: /[\u0064\u24D3\uFF44\u1E0B\u010F\u1E0D\u1E11\u1E13\u1E0F\u0111\u018C\u0256\u0257\uA77A]/g
},
{ base: "dz", letters: /[\u01F3\u01C6]/g },
{
base: "e",
letters: /[\u0065\u24D4\uFF45\u00E8\u00E9\u00EA\u1EC1\u1EBF\u1EC5\u1EC3\u1EBD\u0113\u1E15\u1E17\u0115\u0117\u00EB\u1EBB\u011B\u0205\u0207\u1EB9\u1EC7\u0229\u1E1D\u0119\u1E19\u1E1B\u0247\u025B\u01DD]/g
},
{ base: "f", letters: /[\u0066\u24D5\uFF46\u1E1F\u0192\uA77C]/g },
{
base: "g",
letters: /[\u0067\u24D6\uFF47\u01F5\u011D\u1E21\u011F\u0121\u01E7\u0123\u01E5\u0260\uA7A1\u1D79\uA77F]/g
},
{
base: "h",
letters: /[\u0068\u24D7\uFF48\u0125\u1E23\u1E27\u021F\u1E25\u1E29\u1E2B\u1E96\u0127\u2C68\u2C76\u0265]/g
},
{ base: "hv", letters: /[\u0195]/g },
{
base: "i",
letters: /[\u0069\u24D8\uFF49\u00EC\u00ED\u00EE\u0129\u012B\u012D\u00EF\u1E2F\u1EC9\u01D0\u0209\u020B\u1ECB\u012F\u1E2D\u0268\u0131]/g
},
{ base: "j", letters: /[\u006A\u24D9\uFF4A\u0135\u01F0\u0249]/g },
{
base: "k",
letters: /[\u006B\u24DA\uFF4B\u1E31\u01E9\u1E33\u0137\u1E35\u0199\u2C6A\uA741\uA743\uA745\uA7A3]/g
},
{
base: "l",
letters: /[\u006C\u24DB\uFF4C\u0140\u013A\u013E\u1E37\u1E39\u013C\u1E3D\u1E3B\u017F\u0142\u019A\u026B\u2C61\uA749\uA781\uA747]/g
},
{ base: "lj", letters: /[\u01C9]/g },
{ base: "m", letters: /[\u006D\u24DC\uFF4D\u1E3F\u1E41\u1E43\u0271\u026F]/g },
{
base: "n",
letters: /[\u006E\u24DD\uFF4E\u01F9\u0144\u00F1\u1E45\u0148\u1E47\u0146\u1E4B\u1E49\u019E\u0272\u0149\uA791\uA7A5]/g
},
{ base: "nj", letters: /[\u01CC]/g },
{
base: "o",
letters: /[\u006F\u24DE\uFF4F\u00F2\u00F3\u00F4\u1ED3\u1ED1\u1ED7\u1ED5\u00F5\u1E4D\u022D\u1E4F\u014D\u1E51\u1E53\u014F\u022F\u0231\u00F6\u022B\u1ECF\u0151\u01D2\u020D\u020F\u01A1\u1EDD\u1EDB\u1EE1\u1EDF\u1EE3\u1ECD\u1ED9\u01EB\u01ED\u00F8\u01FF\u0254\uA74B\uA74D\u0275]/g
},
{ base: "oi", letters: /[\u01A3]/g },
{ base: "ou", letters: /[\u0223]/g },
{ base: "oo", letters: /[\uA74F]/g },
{
base: "p",
letters: /[\u0070\u24DF\uFF50\u1E55\u1E57\u01A5\u1D7D\uA751\uA753\uA755]/g
},
{ base: "q", letters: /[\u0071\u24E0\uFF51\u024B\uA757\uA759]/g },
{
base: "r",
letters: /[\u0072\u24E1\uFF52\u0155\u1E59\u0159\u0211\u0213\u1E5B\u1E5D\u0157\u1E5F\u024D\u027D\uA75B\uA7A7\uA783]/g
},
{
base: "s",
letters: /[\u0073\u24E2\uFF53\u00DF\u015B\u1E65\u015D\u1E61\u0161\u1E67\u1E63\u1E69\u0219\u015F\u023F\uA7A9\uA785\u1E9B]/g
},
{
base: "t",
letters: /[\u0074\u24E3\uFF54\u1E6B\u1E97\u0165\u1E6D\u021B\u0163\u1E71\u1E6F\u0167\u01AD\u0288\u2C66\uA787]/g
},
{ base: "tz", letters: /[\uA729]/g },
{
base: "u",
letters: /[\u0075\u24E4\uFF55\u00F9\u00FA\u00FB\u0169\u1E79\u016B\u1E7B\u016D\u00FC\u01DC\u01D8\u01D6\u01DA\u1EE7\u016F\u0171\u01D4\u0215\u0217\u01B0\u1EEB\u1EE9\u1EEF\u1EED\u1EF1\u1EE5\u1E73\u0173\u1E77\u1E75\u0289]/g
},
{ base: "v", letters: /[\u0076\u24E5\uFF56\u1E7D\u1E7F\u028B\uA75F\u028C]/g },
{ base: "vy", letters: /[\uA761]/g },
{
base: "w",
letters: /[\u0077\u24E6\uFF57\u1E81\u1E83\u0175\u1E87\u1E85\u1E98\u1E89\u2C73]/g
},
{ base: "x", letters: /[\u0078\u24E7\uFF58\u1E8B\u1E8D]/g },
{
base: "y",
letters: /[\u0079\u24E8\uFF59\u1EF3\u00FD\u0177\u1EF9\u0233\u1E8F\u00FF\u1EF7\u1E99\u1EF5\u01B4\u024F\u1EFF]/g
},
{
base: "z",
letters: /[\u007A\u24E9\uFF5A\u017A\u1E91\u017C\u017E\u1E93\u1E95\u01B6\u0225\u0240\u2C6C\uA763]/g
}
];
class Idiom {
translate(e, t) {
e = e ?? "";
let s = bundle$1[e] === void 0 ? e : bundle$1[e];
if (t && typeof t == "object")
for (const r in t)
typeof t[r] < "u" && (s = s.replace(
new RegExp("\\${" + r + "}", "g"),
"" + t[r]
));
return s;
}
addBundlePromise(e) {
return this.loadBundlePromise(session.session.currentLanguage, e);
}
addBundle(e, t) {
this.loadBundle(session.session.currentLanguage, e, t);
}
loadBundlePromise(e, t) {
return this.loadBundle(e, t), promises$1[t];
}
loadBundle(e, t, s) {
const r = promises$1[t];
if (r)
s && r.then(s).catch(s);
else {
const i = new Promisified();
promises$1[t] = i.promise;
const o = {};
e && (o["Accept-Language"] = e), transport.http.get(t, { headers: o }).then((a) => {
Object.assign(bundle$1, a), typeof s == "function" && s(), i.resolve();
}).catch((a) => {
typeof s == "function" && s(), i.reject();
});
}
}
addTranslations(e, t) {
notify.onLangReady().promise.then((s) => {
this.loadBundle(s, e + "/" + s + ".json", t);
});
}
addAllTranslations(e) {
return e && e.length > 0 ? notify.onLangReady().promise.then(
(t) => Promise.all(
e.map(
(s) => this.loadBundlePromise(t, s + "/" + t + ".json")
)
)
).then(() => {
}) : Promise.reject();
}
addKeys(e) {
for (const t in e)
typeof bundle$1[t] != "string" && (bundle$1[t] = e[t]);
}
removeAccents(e) {
for (let t = 0; t < defaultDiacriticsRemovalMap$1.length; t++)
e = e.replace(
defaultDiacriticsRemovalMap$1[t].letters,
defaultDiacriticsRemovalMap$1[t].base
);
return e;
}
}
class UserPreferences {
constructor() {
//-------------------------------------
n(this, "data", {});
}
get(e) {
return this.data[e];
}
load(e, t) {
return transport.http.get("/userbook/preference/" + e).then((s) => {
try {
return JSON.parse(s.preference);
} catch {
return t ?? {};
}
}).then((s) => (this.data[e] = s ?? {}, s));
}
update(e, t) {
return t !== void 0 && (this.data[e] = t), this;
}
save(e) {
return transport.http.putJson(
"/userbook/preference/" + e,
this.data[e]
);
}
}
class User {
constructor() {
//-------------------------------------
n(this, "_me", null);
n(this, "_keepOpenOnLogout", !1);
n(this, "_preferences", new UserPreferences());
n(this, "_bookmarkedApps", []);
}
get keepOpenOnLogout() {
return this._keepOpenOnLogout;
}
get preferences() {
return this._preferences;
}
get bookmarkedApps() {
return this._bookmarkedApps;
}
initialize(e) {
return this.loadPublicConf(), notify.onSessionReady().promise.then((t) => {
t && this.setCurrentModel(t);
});
}
setCurrentModel(e) {
this._me = e, this._preferences = new UserPreferences(), this.loadBookmarks();
}
loadPublicConf() {
return transport.http.get("/conf/public").then((e) => (this._keepOpenOnLogout = (e == null ? void 0 : e.keepOpenOnLogout) || !1, e));
}
/** Bookmarks : pinned apps */
async loadBookmarks() {
await transport.http.get("/userbook/preference/apps").then((e) => {
e.preference || (e.preference = null);
const t = JSON.parse(
e.preference
);
let s;
if (t && t.length && typeof t.concat == "function") {
this._bookmarkedApps = t, s = {
bookmarks: t.map((o) => o.name),
applications: []
}, transport.http.putJson("/userbook/preference/apps", s);
return;
} else
s = t;
s || (s = {
bookmarks: [],
applications: []
});
let r = !0;
const i = [];
s.bookmarks.forEach((o, a) => {
const c = this._me.apps.find((h) => h.name === o);
if (c) {
const h = Object.assign({}, c);
this._bookmarkedApps.push(h);
} else
i.push(o), r = !1;
}), i.forEach((o) => {
const a = s.bookmarks.indexOf(o);
a !== -1 && s.bookmarks.splice(a, 1);
}), r || transport.http.putJson("/userbook/preference/apps", s);
});
}
loadAppPrefs(e) {
return this.preferences.load(e, {});
}
saveAppPrefs(e) {
return this.preferences.save(e);
}
loadLanguage() {
return this.preferences.load("language", { "default-domain": session.session.currentLanguage }).then((e) => e["default-domain"]);
}
saveLanguage(e) {
return this.preferences.update("language", { "default-domain": e }).save("language");
}
}
const http$1 = transport == null ? void 0 : transport.http;
class AppConf {
constructor() {
//-------------------------------------
n(this, "_publicConf", {});
n(this, "_currentApp");
n(this, "_appConf", {});
}
/**
* Get the currently initialized App.
* @see getter SessionFramework.currentApp
*/
get currentApp() {
return this._currentApp ?? null;
}
setCurrentApp(e) {
return this._currentApp = e, this;
}
async initialize(e, t = !1) {
t || this.setCurrentApp(e), await Promise.all([this.getPublicConf(e), this.loadI18n(e)]);
}
async getPublicConf(e) {
return this._publicConf[e] || (this._publicConf[e] = await http$1.get(`/${e}/conf/public`, {
queryParams: { _: configure.Platform.deploymentTag }
})), this._publicConf[e];
}
async getWebAppConf(e) {
let t;
return this._appConf[e] || (await http$1.get(
"/applications-list"
)).apps.forEach((r) => {
if (r != null && r.prefix) {
const i = r.prefix.replace("/", "");
this._appConf[i] = r;
} else r != null && r.name && r.name.toLowerCase() == e && (t = r);
}), this._appConf[e] ?? t;
}
async loadI18n(e) {
return await notify.onLangReady().promise, configure.Platform.idiom.addBundlePromise(`/${e}/i18n`);
}
}
class Analytics {
constructor() {
//-------------------------------------
n(this, "_status", "void");
n(this, "_params");
}
get status() {
return this._status;
}
xiti() {
return this.parametersWithCheck("xiti", !1);
}
parameters(e) {
return this.parametersWithCheck(e, !0);
}
async parametersWithCheck(e, t) {
return this.initialize().promise.then((s) => !t || s.type === e || s.type === "multiple" ? s[e] : void 0);
}
/**
* This method loads the conf and waits for the user session to start.
* It can be called ASAP, but it will be automatically called if needed.
* @returns A promise of the end of the init process (it may throw errors)
* @throws ERROR_CODE.MALFORMED_DATA when config cannot be read.
*/
initialize() {
return this._params || (this._params = notify.promisify(), this._status = "pending", Promise.all([
transport.http.get("/analyticsConf"),
//FIXME change servers config to only keep the "all-in-one" query to /analyticsConf.
transport.http.get("/xiti/config")
]).then(async (e) => {
var t;
if (!e || !e[0] || !e[0].type)
throw ERROR_CODE.MALFORMED_DATA;
e[1] && e[1].active && (e[0].xiti = await this.initializeXiti(e[1])), (t = this._params) == null || t.resolve(e[0]), this._status = "ready";
}).catch((e) => {
var t;
throw this._status = "failed", (t = this._params) == null || t.reject(), e;
})), this._params;
}
/** 2021 implementation of XiTi. */
async initializeXiti(e) {
if (!e.structureMap || !configure.Platform.apps.currentApp) return;
const t = await notify.onSessionReady().promise, s = session.session.description;
let r;
for (const h of t.structures) {
const l = e.structureMap[h];
if (l && l.collectiviteId && l.UAI) {
r = l;
break;
}
}
if (!r || !r.active) return;
const i = await configure.Platform.apps.getPublicConf(
configure.Platform.apps.currentApp
);
if (!i) return;
const o = i.xiti;
if (!o || !o.LIBELLE_SERVICE || !r.UAI) return;
function a(h) {
let l = "";
for (let E = 0; E < h.length; E++)
l += h.charCodeAt(E);
return l;
}
const c = {
Student: "ELEVE",
Teacher: "ENSEIGNANT",
Relative: "PARENT",
Personnel: "ADMIN_VIE_SCOL_TECH",
Guest: "AUTRE"
};
return {
LIBELLE_SERVICE: o.LIBELLE_SERVICE,
// Which property of LIBELLE_SERVICE to use depends on the frontend.
TYPE: o.OUTIL ? "TIERS" : "NATIF",
OUTIL: o.OUTIL ? o.OUTIL : "",
STRUCT_ID: r.collectiviteId,
STRUCT_UAI: r.UAI,
PROJET: r.projetId ? r.projetId : e.ID_PROJET,
EXPLOITANT: e.ID_EXPLOITANT,
PLATFORME: r.plateformeId ? r.plateformeId : e.ID_PLATEFORME,
ID_PERSO: a(t.userId),
PROFILE: s.profiles && s.profiles.length > 0 ? c[s.profiles[0]] ?? "" : ""
};
}
}
class ConfigurationFramework {
constructor() {
//-------------------------------------
n(this, "Platform", {
deploymentTag: "",
cdnDomain: "",
apps: new AppConf(),
theme: new Theme(),
analytics: new Analytics(),
idiom: new Idiom(),
listLanguages: () => transport.http.get("/languages")
});
n(this, "School", {
//apps; -> pinnedApps;
});
n(this, "User", new User());
}
async initialize(e, t) {
if (!e) {
const r = (h) => (h < 10 ? "0" : "") + h.toFixed(0), i = /* @__PURE__ */ new Date(), o = i.getFullYear(), a = i.getMonth() + 1, c = i.getDate();
e = `${o}${r(a)}${r(c)}`;
}
const s = e;
this.Platform.deploymentTag = e, typeof t == "string" && t.length > 0 && (this.Platform.cdnDomain = t), transport.http.setCdn(this.Platform.cdnDomain), await Promise.all([
this.Platform.theme.initialize(s),
notify.onSessionReady().promise.then(
(r) => this.Platform.idiom.addBundlePromise("/i18n")
),
//TODO this.School.initialize( v ),
this.User.initialize(s)
]);
}
// async mount(
// version?: string | null,
// cdnDomain?: string | null,
// ): Promise<void> {
// // If version is undefined, default to a new tag every day.
// if (!version) {
// const padWith0 = (val: number): string =>
// (val < 10 ? "0" : "") + val.toFixed(0);
// const now = new Date();
// const y = now.getFullYear();
// const m = now.getMonth() + 1;
// const d = now.getDate();
// version = `${y}${padWith0(m)}${padWith0(d)}`; //FIXME add ${h.toFixed(0)} to change the tag every 10 minutes
// }
// const v = version;
// this.Platform.deploymentTag = version;
// // Don't overwrite the CDN domain with a null or empty value.
// if (typeof cdnDomain === "string" && cdnDomain.length > 0) {
// this.Platform.cdnDomain = cdnDomain;
// }
// transport.http.setCdn(this.Platform.cdnDomain);
// //
// await this.Platform.idiom.addBundlePromise("/i18n");
// }
}
const configure = new ConfigurationFramework(), http = transport == null ? void 0 : transport.http;
var D;
const me = (D = session == null ? void 0 : session.session) == null ? void 0 : D.user;
class Notification {
constructor(e) {
n(this, "_id");
n(this, "model");
e.reported = e.reporters && e.reporters.length > 0, this._id = e._id, this.model = e;
}
isUnread() {
var e;
return ((e = this.model.recipients) == null ? void 0 : e.find((t) => t.userId === me.userId)) !== void 0;
}
delete() {
return http.delete("/timeline/" + this._id);
}
discard() {
return http.put("/timeline/" + this._id);
}
report() {
return http.put("/timeline/" + this._id + "/report");
}
}
class TimelineApp {
constructor() {
//-------------------------------------
n(this, "_notifications", []);
n(this, "_notificationTypes", []);
// ex: ["BLOG"]
n(this, "_flashMessages", []);
n(this, "_pageNumber", 0);
n(this, "_lastPage", !1);
n(this, "_loading", !1);
n(this, "showMine", !1);
}
get notifications() {
return this._notifications;
}
get isLoading() {
return this._loading;
}
get page() {
return this._pageNumber;
}
get hasMorePage() {
return !this._lastPage;
}
get notificationTypes() {
return this._notificationTypes;
}
get selectedNotificationTypes() {
return this.preferences.type = this.preferences.type || [], this.preferences.type;
}
get preferences() {
return configure.User.preferences.get(APP$4.TIMELINE);
}
get flashMessages() {
return this._flashMessages;
}
savePreferences() {
return configure.User.saveAppPrefs(APP$4.TIMELINE);
}
resetPagination() {
this._pageNumber = 0, this._lastPage = !1, this._loading = !1;
}
initialize() {
return Promise.all([
configure.User.loadAppPrefs(APP$4.TIMELINE),
transport.http.get("/timeline/types")
]).then((e) => {
this._notificationTypes = e[1];
});
}
loadNotifications(e) {
if (this._loading || this._lastPage)
return Promise.resolve();
e && (this._pageNumber++, this._lastPage = !1);
const t = this.selectedNotificationTypes;
if (t.length === 0)
return this._lastPage = !0, Promise.resolve();
const s = {
page: this.page,
mine: 1
};
return this.showMine || delete s.mine, this._loading = !0, transport.http.get(`/timeline/lastNotifications?type=${t.join("&type=")}`, {
queryParams: s
}).then(
(r) => {
if (this._loading = !1, r.status === "ok")
if (r.number && r.results) {
const i = r.results.filter(
(o) => this._notifications.findIndex(
(a) => a._id === o._id
) === -1
).map((o) => new Notification(o));
this._notifications = this._notifications.concat(i), this._pageNumber++;
} else
this._lastPage = !0;
}
).catch((r) => {
this._loading = !1;
});
}
loadFlashMessages() {
return transport.http.get("/timeline/flashmsg/listuser").then((e) => {
this._flashMessages = e;
});
}
markAsRead(e) {
return transport.http.put("/timeline/flashmsg/" + e.id + "/markasread");
}
}
class ITimelineFactory {
//-------------------------------------
static createInstance() {
return new TimelineApp();
}
}
const ReactionTypes = [
"REACTION_1",
"REACTION_2",
"REACTION_3",
"REACTION_4"
];
class NotifyFrameworkFactory {
static instance() {
return notify;
}
}
const LAYER_NAME = {
WIDGETS: "widgets",
EXPLORER: "explorer",
TRANSPORT: "transport",
WEB_DATA: "webDataPipeline"
}, EVENT_NAME = {
USERPREF_CHANGED: "userprefChanged",
SEARCH_RESULTED: "searchResulted",
ERROR_OCCURED: "error",
DATA_TRACKED: "track"
};
class ServiceRegistry extends Map {
/** Register a service */
register({
application: e,
resourceType: t
}, s) {
this.set(`${e}:main`, s), this.set(`${e}:${t}`, s);
}
/** Lookup for a service */
findService(e, t) {
return this.lookupService(e, t);
}
/** Lookup for a main service */
findMainService({ application: e }, t) {
return this.lookupService({ application: e, resourceType: "main" }, t);
}
/** Check if a service is registered. */
isRegistered({
application: e,
resourceType: t
}) {
return this.get(`${e}:${t}`) !== void 0;
}
/** Private lookup for a service */
lookupService({
application: e,
resourceType: t
}, s) {
const r = this.get(`${e}:${t}`);
if (r === void 0)
throw `Service not found: ${e}:${t}`;
return r(s);
}
}
const m = class m {
//
// IMPLEMENTATION
//
constructor(e) {
//
// PROTECTED HELPERS
//
n(this, "checkHttpResponse", (e) => {
if (this.http.latestResponse.status >= 300)
throw this.http.latestResponse.statusText;
return e;
});
this.context = e;
}
get http() {
return this.context.http();
}
async copy(e) {
const t = await this.http.post("/archive/duplicate", {
application: e.application,
resourceId: e.resourceId
});
return this.checkHttpResponse(t);
}
async publish(e) {
const t = new FormData();
return t.append("title", e.title), t.append("cover", e.cover), t.append("coverName", e.cover.name), t.append("coverType", e.cover.type), t.append("teacherAvatar", e.teacherAvatar), t.append(
"teacherAvatarName",
e.teacherAvatar.name || `teacherAvatar_${e.userId}`
), t.append(
"teacherAvatarType",
e.teacherAvatar.type
), t.append("language", e.language), e.activityType.forEach((i) => {
t.append("activityType[]", i);
}), e.subjectArea.forEach((i) => {
t.append("subjectArea[]", i);
}), e.age.forEach((i) => {
t.append("age[]", i.toString());
}), t.append("description", e.description), e.keyWords.split(",").forEach((i) => {
t.append("keyWords[]", i.trim());
}), t.append("licence", e.licence), t.append(
"pdfUri",
`${window.location.origin}${this.getPrintUrl(e.resourceEntId)}`
), t.append(
"application",
e.application ? e.application : ""
), t.append("resourceId", e.resourceId), t.append("teacherSchool", e.userStructureName), await this.http.post(
"/appregistry/library/resource",
t,
{
headers: { "Content-Type": "multipart/form-data" }
}
);
}
//
// FOLDER METHODS
//
async createContext(e) {
const t = await this.http.get("/explorer/context", {
queryParams: this.toQueryParams(e)
});
return this.checkHttpResponse(t);
}
async searchContext(e) {
const t = await this.http.get(
"/explorer/resources",
{
queryParams: this.toQueryParams(e)
}
);
return this.checkHttpResponse(t);
}
async searchResource(e) {
const t = await this.http.get(
`/explorer/resources/${e.id}`,
{
queryParams: this.getResourceParams(e)
}
);
return this.checkHttpResponse(t);
}
async createFolder(e) {
const t = await this.http.post(
"/explorer/folders",
this.createFolderToBodyParams(e)
);
return this.checkHttpResponse(t);
}
async updateFolder(e) {
const t = await this.http.put(
`/explorer/folders/${e.folderId}`,
this.createFolderToBodyParams(e)
);
return this.checkHttpResponse(t);
}
async moveToFolder(e, t = !1) {
e.resourceIds = t ? await this.mapAssetIdToIds({
application: e.application,
assetIds: e.resourceIds
}) : e.resourceIds;
const s = await this.http.post(
`/explorer/folders/${e.folderId}/move`,
this.moveToBodyParams(e)
);
return this.checkHttpResponse(s);
}
async listSubfolders(e) {
const t = await this.http.get(
`/explorer/folders/${e}`
);
return this.checkHttpResponse(t);
}
async deleteAll(e, t = !1) {
e.resourceIds = t ? await this.mapAssetIdToIds({
application: e.application,
assetIds: e.resourceIds
}) : e.resourceIds;
const s = await this.http.deleteJson(
"/explorer",
e
);
return this.checkHttpResponse(s);
}
async trashAll({ resourceType: e, ...t }, s = !1) {
t.resourceIds = s ? await this.mapAssetIdToIds({
application: t.application,
assetIds: t.resourceIds
}) : t.resourceIds;
const r = await this.http.putJson(
"/explorer/trash",
t
);
return this.checkHttpResponse(r);
}
/** Trash folders and/or resources. */
async restoreAll({ resourceType: e, ...t }, s = !1) {
t.resourceIds = s ? await this.mapAssetIdToIds({
application: t.application,
assetIds: t.resourceIds
}) : t.resourceIds;
const r = await this.http.putJson(
"/explorer/restore",
t
);
return this.checkHttpResponse(r);
}
async mapAssetIdToIds({
application: e,
assetIds: t
}) {
const s = await this.searchContext({
application: e,
pagination: { startIdx: 0, pageSize: t.length + 1 },
types: [],
filters: {},
asset_id: t
});
return t.map((r) => {
const i = s.resources.find(
(o) => o.assetId === r
);
if (i === void 0)
throw "explorer.assetid.notfound";
return i.id;
});
}
async getThumbnailPath(e) {
if (typeof e > "u")
return e;
if