@entur-partner/micro-frontend 2.6.2-alpha.0 → 2.6.2-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AppProvider.d.ts +24 -24
- package/dist/Payload.d.ts +43 -43
- package/dist/User.d.ts +19 -19
- package/dist/events.d.ts +27 -27
- package/dist/index.d.ts +5 -5
- package/dist/micro-frontend.cjs.development.js +188 -408
- package/dist/micro-frontend.cjs.development.js.map +1 -1
- package/dist/micro-frontend.cjs.production.min.js +1 -1
- package/dist/micro-frontend.cjs.production.min.js.map +1 -1
- package/dist/micro-frontend.esm.js +186 -402
- package/dist/micro-frontend.esm.js.map +1 -1
- package/dist/registerMicroFrontend.d.ts +8 -8
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"micro-frontend.cjs.development.js","sources":["../src/AppProvider.tsx","../src/events.ts","../src/registerMicroFrontend.tsx"],"sourcesContent":["import type { Permission } from \"@entur-partner/permission-client-node\";\nimport { assertIsDefined } from \"@entur-partner/util\";\nimport React, {\n\ttype FC,\n\ttype ReactNode,\n\tuseContext,\n\tuseEffect,\n\tuseState,\n} from \"react\";\n\nimport type { User } from \"./User\";\n\ninterface AppContextType {\n\tgetToken: () => Promise<string>;\n\tuser: User;\n\tlogout?: () => void;\n\tactiveOrgId: number;\n\tnavigate: (path: string) => void;\n}\n\nexport const AppContext = React.createContext<AppContextType | undefined>(\n\tundefined,\n);\n\nexport const useUser = () => {\n\tconst context = useContext(AppContext);\n\tassertIsDefined(context);\n\treturn context.user;\n};\n\nexport const useActiveOrgId = () => {\n\tconst context = useContext(AppContext);\n\tassertIsDefined(context);\n\treturn context.activeOrgId;\n};\n\nexport interface AppProviderProps {\n\tchildren: ReactNode;\n\tgetToken: () => Promise<string>;\n\tuser: User;\n\tgetPermissions: () => Promise<Permission[]>;\n\torganisationId: string;\n\tnavigate: (path: string) => void;\n}\n\nexport const useNavigate = () => {\n\tconst context = useContext(AppContext);\n\tassertIsDefined(context);\n\treturn context.navigate;\n};\n\nexport const AppProvider: FC<AppProviderProps> = ({\n\tchildren,\n\torganisationId,\n\tgetPermissions,\n\t...rest\n}) => {\n\tconst [permissions, setPermissions] = useState<Permission[]>([]);\n\n\tuseEffect(() => {\n\t\tasync function fetchData() {\n\t\t\ttry {\n\t\t\t\tconst fetchedPermissions = await getPermissions();\n\t\t\t\tsetPermissions(fetchedPermissions);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t\"Fetching permissions with the provided getPermissions function failed in AppProvider with the following error:\",\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tfetchData();\n\t}, [getPermissions]);\n\n\treturn (\n\t\t<AppContext.Provider\n\t\t\tvalue={{\n\t\t\t\t...rest,\n\t\t\t\tuser: { ...rest.user, permissions: permissions },\n\t\t\t\tactiveOrgId: Number(organisationId),\n\t\t\t}}\n\t\t>\n\t\t\t{children}\n\t\t</AppContext.Provider>\n\t);\n};\n","import type { MicroFrontendPayload } from \"./Payload\";\n\ntype MountEventDetail = {\n\tid: string;\n\tmountPoint: HTMLDivElement;\n\tpayload: MicroFrontendPayload;\n};\n\ntype UnmountEventDetail = {\n\tid: string;\n\tmountPoint: HTMLDivElement;\n};\n\nexport const MOUNT_EVENT_TYPE = \"@entur-partner:mount\";\nexport const UNMOUNT_EVENT_TYPE = \"@entur-partner:unmount\";\n\nexport interface MountEvent extends CustomEvent<MountEventDetail> {}\nexport interface UnmountEvent extends CustomEvent<UnmountEventDetail> {}\n\nexport function createMountEvent(detail: MountEventDetail) {\n\treturn new CustomEvent<MountEventDetail>(MOUNT_EVENT_TYPE, { detail });\n}\n\nexport function createUnmountEvent(detail: UnmountEventDetail) {\n\treturn new CustomEvent<UnmountEventDetail>(UNMOUNT_EVENT_TYPE, { detail });\n}\n\nexport const ROUTE_CHANGE_EVENT_TYPE = \"@entur-partner:after-route-change\";\n\nexport type RouteAction = \"PUSH\" | \"POP\" | \"REPLACE\";\n\ntype RouteChangeEventDetail = {\n\tlocation: Location;\n\taction: RouteAction;\n};\n\nexport class RouteChangeEvent extends CustomEvent<RouteChangeEventDetail> {}\n","/*global EventListener*/\n\nimport {\n\tMOUNT_EVENT_TYPE,\n\ttype MountEvent,\n\tUNMOUNT_EVENT_TYPE,\n\ttype UnmountEvent,\n} from \"./events\";\nimport type { MicroFrontendPayload } from \"./Payload\";\n\ninterface Config {\n\tmicroFrontendId: string;\n\tmount: (\n\t\tmountPoint: HTMLDivElement,\n\t\tpayload: MicroFrontendPayload,\n\t\tdeprecatedMountPoint: HTMLDivElement,\n\t) => void;\n\tunmount: (mountPoint: HTMLDivElement) => void;\n}\n\nexport function registerMicroFrontend(config: Config): void {\n\tconst { unmount, microFrontendId, mount } = config;\n\n\twindow.addEventListener(MOUNT_EVENT_TYPE, ((event: MountEvent) => {\n\t\tif (!event.detail.id.startsWith(microFrontendId)) {\n\t\t\treturn;\n\t\t}\n\t\tmount(\n\t\t\tevent.detail.mountPoint,\n\t\t\tevent.detail.payload,\n\t\t\tevent.detail.mountPoint,\n\t\t);\n\t}) as EventListener);\n\n\twindow.addEventListener(UNMOUNT_EVENT_TYPE, ((event: UnmountEvent) => {\n\t\tif (!event.detail.id.startsWith(microFrontendId)) {\n\t\t\treturn;\n\t\t}\n\t\tunmount(event.detail.mountPoint);\n\t}) as EventListener);\n}\n"],"names":["AppContext","React","createContext","undefined","useUser","context","useContext","assertIsDefined","user","useActiveOrgId","activeOrgId","useNavigate","navigate","AppProvider","_ref","children","organisationId","getPermissions","rest","_objectWithoutPropertiesLoose","_excluded","_useState","useState","permissions","setPermissions","useEffect","fetchData","_fetchData","apply","arguments","_asyncToGenerator","
|
|
1
|
+
{"version":3,"file":"micro-frontend.cjs.development.js","sources":["../src/AppProvider.tsx","../src/events.ts","../src/registerMicroFrontend.tsx"],"sourcesContent":["import type { Permission } from \"@entur-partner/permission-client-node\";\nimport { assertIsDefined } from \"@entur-partner/util\";\nimport React, {\n\ttype FC,\n\ttype ReactNode,\n\tuseContext,\n\tuseEffect,\n\tuseState,\n} from \"react\";\n\nimport type { User } from \"./User\";\n\ninterface AppContextType {\n\tgetToken: () => Promise<string>;\n\tuser: User;\n\tlogout?: () => void;\n\tactiveOrgId: number;\n\tnavigate: (path: string) => void;\n}\n\nexport const AppContext = React.createContext<AppContextType | undefined>(\n\tundefined,\n);\n\nexport const useUser = () => {\n\tconst context = useContext(AppContext);\n\tassertIsDefined(context);\n\treturn context.user;\n};\n\nexport const useActiveOrgId = () => {\n\tconst context = useContext(AppContext);\n\tassertIsDefined(context);\n\treturn context.activeOrgId;\n};\n\nexport interface AppProviderProps {\n\tchildren: ReactNode;\n\tgetToken: () => Promise<string>;\n\tuser: User;\n\tgetPermissions: () => Promise<Permission[]>;\n\torganisationId: string;\n\tnavigate: (path: string) => void;\n}\n\nexport const useNavigate = () => {\n\tconst context = useContext(AppContext);\n\tassertIsDefined(context);\n\treturn context.navigate;\n};\n\nexport const AppProvider: FC<AppProviderProps> = ({\n\tchildren,\n\torganisationId,\n\tgetPermissions,\n\t...rest\n}) => {\n\tconst [permissions, setPermissions] = useState<Permission[]>([]);\n\n\tuseEffect(() => {\n\t\tasync function fetchData() {\n\t\t\ttry {\n\t\t\t\tconst fetchedPermissions = await getPermissions();\n\t\t\t\tsetPermissions(fetchedPermissions);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t\"Fetching permissions with the provided getPermissions function failed in AppProvider with the following error:\",\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tfetchData();\n\t}, [getPermissions]);\n\n\treturn (\n\t\t<AppContext.Provider\n\t\t\tvalue={{\n\t\t\t\t...rest,\n\t\t\t\tuser: { ...rest.user, permissions: permissions },\n\t\t\t\tactiveOrgId: Number(organisationId),\n\t\t\t}}\n\t\t>\n\t\t\t{children}\n\t\t</AppContext.Provider>\n\t);\n};\n","import type { MicroFrontendPayload } from \"./Payload\";\n\ntype MountEventDetail = {\n\tid: string;\n\tmountPoint: HTMLDivElement;\n\tpayload: MicroFrontendPayload;\n};\n\ntype UnmountEventDetail = {\n\tid: string;\n\tmountPoint: HTMLDivElement;\n};\n\nexport const MOUNT_EVENT_TYPE = \"@entur-partner:mount\";\nexport const UNMOUNT_EVENT_TYPE = \"@entur-partner:unmount\";\n\nexport interface MountEvent extends CustomEvent<MountEventDetail> {}\nexport interface UnmountEvent extends CustomEvent<UnmountEventDetail> {}\n\nexport function createMountEvent(detail: MountEventDetail) {\n\treturn new CustomEvent<MountEventDetail>(MOUNT_EVENT_TYPE, { detail });\n}\n\nexport function createUnmountEvent(detail: UnmountEventDetail) {\n\treturn new CustomEvent<UnmountEventDetail>(UNMOUNT_EVENT_TYPE, { detail });\n}\n\nexport const ROUTE_CHANGE_EVENT_TYPE = \"@entur-partner:after-route-change\";\n\nexport type RouteAction = \"PUSH\" | \"POP\" | \"REPLACE\";\n\ntype RouteChangeEventDetail = {\n\tlocation: Location;\n\taction: RouteAction;\n};\n\nexport class RouteChangeEvent extends CustomEvent<RouteChangeEventDetail> {}\n","/*global EventListener*/\n\nimport {\n\tMOUNT_EVENT_TYPE,\n\ttype MountEvent,\n\tUNMOUNT_EVENT_TYPE,\n\ttype UnmountEvent,\n} from \"./events\";\nimport type { MicroFrontendPayload } from \"./Payload\";\n\ninterface Config {\n\tmicroFrontendId: string;\n\tmount: (\n\t\tmountPoint: HTMLDivElement,\n\t\tpayload: MicroFrontendPayload,\n\t\tdeprecatedMountPoint: HTMLDivElement,\n\t) => void;\n\tunmount: (mountPoint: HTMLDivElement) => void;\n}\n\nexport function registerMicroFrontend(config: Config): void {\n\tconst { unmount, microFrontendId, mount } = config;\n\n\twindow.addEventListener(MOUNT_EVENT_TYPE, ((event: MountEvent) => {\n\t\tif (!event.detail.id.startsWith(microFrontendId)) {\n\t\t\treturn;\n\t\t}\n\t\tmount(\n\t\t\tevent.detail.mountPoint,\n\t\t\tevent.detail.payload,\n\t\t\tevent.detail.mountPoint,\n\t\t);\n\t}) as EventListener);\n\n\twindow.addEventListener(UNMOUNT_EVENT_TYPE, ((event: UnmountEvent) => {\n\t\tif (!event.detail.id.startsWith(microFrontendId)) {\n\t\t\treturn;\n\t\t}\n\t\tunmount(event.detail.mountPoint);\n\t}) as EventListener);\n}\n"],"names":["AppContext","React","createContext","undefined","useUser","context","useContext","assertIsDefined","user","useActiveOrgId","activeOrgId","useNavigate","navigate","AppProvider","_ref","children","organisationId","getPermissions","rest","_objectWithoutPropertiesLoose","_excluded","_useState","useState","permissions","setPermissions","useEffect","fetchData","_fetchData","apply","arguments","_asyncToGenerator","_regenerator","m","_callee","fetchedPermissions","_t","w","_context","p","n","v","console","error","a","createElement","Provider","value","_extends","Number","MOUNT_EVENT_TYPE","UNMOUNT_EVENT_TYPE","createMountEvent","detail","CustomEvent","createUnmountEvent","ROUTE_CHANGE_EVENT_TYPE","RouteChangeEvent","_CustomEvent","_inheritsLoose","_wrapNativeSuper","registerMicroFrontend","config","unmount","microFrontendId","mount","window","addEventListener","event","id","startsWith","mountPoint","payload"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBO,IAAMA,UAAU,gBAAGC,KAAK,CAACC,aAAa,CAC5CC,SAAS,CACT,CAAA;IAEYC,OAAO,GAAG,SAAVA,OAAOA,GAAQ;AAC3B,EAAA,IAAMC,OAAO,GAAGC,gBAAU,CAACN,UAAU,CAAC,CAAA;EACtCO,oBAAe,CAACF,OAAO,CAAC,CAAA;EACxB,OAAOA,OAAO,CAACG,IAAI,CAAA;AACpB,EAAC;IAEYC,cA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,KAAA;AACAC,IAAAA,KAAK,CACJG,KAAK,CAACf,MAAM,CAACkB,UAAU,EACvBH,KAAK,CAACf,MAAM,CAACmB,OAAO,EACpBJ,KAAK,CAACf,MAAM,CAACkB,UAAU,CACvB,CAAA;AACF,GAAmB,CAAC,CAAA;AAEpBL,EAAAA,MAAM,CAACC,gBAAgB,CAAChB,kBAAkB,EAAG,UAACiB,KAAmB,EAAI;IACpE,IAAI,CAACA,KAAK,CAACf,MAAM,CAACgB,EAAE,CAACC,UAAU,CAACN,eAAe,CAAC,EAAE;AACjD,MAAA,OAAA;AACD,KAAA;AACAD,IAAAA,OAAO,CAACK,KAAK,CAACf,MAAM,CAACkB,UAAU,CAAC,CAAA;AACjC,GAAmB,CAAC,CAAA;AACrB;;;;;;;;;;;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@entur-partner/util"),e=require("react");function r(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var n=r(e);function o(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(o=function(){return!!t})()}function i(){i=function(){return e};var t,e={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},a="function"==typeof Symbol?Symbol:{},u=a.iterator||"@@iterator",c=a.asyncIterator||"@@asyncIterator",s=a.toStringTag||"@@toStringTag";function f(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{f({},"")}catch(t){f=function(t,e,r){return t[e]=r}}function l(t,e,r,n){var i=Object.create((e&&e.prototype instanceof m?e:m).prototype),a=new k(n||[]);return o(i,"_invoke",{value:j(t,r,a)}),i}function p(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=l;var h="suspendedStart",v="suspendedYield",y="executing",d="completed",g={};function m(){}function w(){}function b(){}var x={};f(x,u,(function(){return this}));var E=Object.getPrototypeOf,O=E&&E(E(C([])));O&&O!==r&&n.call(O,u)&&(x=O);var _=b.prototype=m.prototype=Object.create(x);function L(t){["next","throw","return"].forEach((function(e){f(t,e,(function(t){return this._invoke(e,t)}))}))}function P(t,e){function r(o,i,a,u){var c=p(t[o],t,i);if("throw"!==c.type){var s=c.arg,f=s.value;return f&&"object"==typeof f&&n.call(f,"__await")?e.resolve(f.__await).then((function(t){r("next",t,a,u)}),(function(t){r("throw",t,a,u)})):e.resolve(f).then((function(t){s.value=t,a(s)}),(function(t){return r("throw",t,a,u)}))}u(c.arg)}var i;o(this,"_invoke",{value:function(t,n){function o(){return new e((function(e,o){r(t,n,e,o)}))}return i=i?i.then(o,o):o()}})}function j(e,r,n){var o=h;return function(i,a){if(o===y)throw Error("Generator is already running");if(o===d){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var u=n.delegate;if(u){var c=N(u,n);if(c){if(c===g)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===h)throw o=d,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=y;var s=p(e,r,n);if("normal"===s.type){if(o=n.done?d:v,s.arg===g)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o=d,n.method="throw",n.arg=s.arg)}}}function N(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,N(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),g;var i=p(o,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,g;var a=i.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,g):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,g)}function T(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function I(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function k(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(T,this),this.reset(!0)}function C(e){if(e||""===e){var r=e[u];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,i=function r(){for(;++o<e.length;)if(n.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return i.next=i}}throw new TypeError(typeof e+" is not iterable")}return w.prototype=b,o(_,"constructor",{value:b,configurable:!0}),o(b,"constructor",{value:w,configurable:!0}),w.displayName=f(b,s,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===w||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,b):(t.__proto__=b,f(t,s,"GeneratorFunction")),t.prototype=Object.create(_),t},e.awrap=function(t){return{__await:t}},L(P.prototype),f(P.prototype,c,(function(){return this})),e.AsyncIterator=P,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new P(l(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},L(_),f(_,s,"Generator"),f(_,u,(function(){return this})),f(_,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=C,k.prototype={constructor:k,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(I),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function o(n,o){return u.type="throw",u.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],u=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var c=n.call(a,"catchLoc"),s=n.call(a,"finallyLoc");if(c&&s){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!s)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,g):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),g},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),I(r),g}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;I(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:C(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),g}},e}function a(t,e,r,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}function u(){return u=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},u.apply(this,arguments)}function c(t){return c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},c(t)}function s(t,e){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},s(t,e)}function f(t){var e="function"==typeof Map?new Map:void 0;return f=function(t){if(null===t||!function(t){try{return-1!==Function.toString.call(t).indexOf("[native code]")}catch(e){return"function"==typeof t}}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return function(t,e,r){if(o())return Reflect.construct.apply(null,arguments);var n=[null];n.push.apply(n,e);var i=new(t.bind.apply(t,n));return r&&s(i,r.prototype),i}(t,arguments,c(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),s(r,t)},f(t)}var l=["children","organisationId","getPermissions"],p=n.default.createContext(void 0),h="@entur-partner:mount",v="@entur-partner:unmount",y=function(t){function e(){return t.apply(this,arguments)||this}var r,n;return n=t,(r=e).prototype=Object.create(n.prototype),r.prototype.constructor=r,s(r,n),e}(f(CustomEvent));exports.AppProvider=function(t){var r=t.children,o=t.organisationId,c=t.getPermissions,s=function(t,e){if(null==t)return{};var r,n,o={},i=Object.keys(t);for(n=0;n<i.length;n++)e.indexOf(r=i[n])>=0||(o[r]=t[r]);return o}(t,l),f=e.useState([]),h=f[0],v=f[1];return e.useEffect((function(){function t(){var e;return e=i().mark((function t(){return i().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,c();case 3:v(t.sent),t.next=10;break;case 7:t.prev=7,t.t0=t.catch(0),console.error("Fetching permissions with the provided getPermissions function failed in AppProvider with the following error:",t.t0);case 10:case"end":return t.stop()}}),t,null,[[0,7]])})),t=function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function u(t){a(i,n,o,u,c,"next",t)}function c(t){a(i,n,o,u,c,"throw",t)}u(void 0)}))},t.apply(this,arguments)}!function(){t.apply(this,arguments)}()}),[c]),n.default.createElement(p.Provider,{value:u({},s,{user:u({},s.user,{permissions:h}),activeOrgId:Number(o)})},r)},exports.MOUNT_EVENT_TYPE=h,exports.ROUTE_CHANGE_EVENT_TYPE="@entur-partner:after-route-change",exports.RouteChangeEvent=y,exports.UNMOUNT_EVENT_TYPE=v,exports.createMountEvent=function(t){return new CustomEvent(h,{detail:t})},exports.createUnmountEvent=function(t){return new CustomEvent(v,{detail:t})},exports.registerMicroFrontend=function(t){var e=t.unmount,r=t.microFrontendId,n=t.mount;window.addEventListener(h,(function(t){t.detail.id.startsWith(r)&&n(t.detail.mountPoint,t.detail.payload,t.detail.mountPoint)})),window.addEventListener(v,(function(t){t.detail.id.startsWith(r)&&e(t.detail.mountPoint)}))},exports.useActiveOrgId=function(){var r=e.useContext(p);return t.assertIsDefined(r),r.activeOrgId},exports.useNavigate=function(){var r=e.useContext(p);return t.assertIsDefined(r),r.navigate},exports.useUser=function(){var r=e.useContext(p);return t.assertIsDefined(r),r.user};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@entur-partner/util"),e=require("react");function n(t,e,n,r,o,i,u){try{var c=t[i](u),a=c.value}catch(t){return void n(t)}c.done?e(a):Promise.resolve(a).then(r,o)}function r(){return r=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)({}).hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},r.apply(null,arguments)}function o(t){return o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},o(t)}function i(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(i=function(){return!!t})()}function u(){var t,e,n="function"==typeof Symbol?Symbol:{},r=n.iterator||"@@iterator",o=n.toStringTag||"@@toStringTag";function i(n,r,o,i){var u=Object.create((r&&r.prototype instanceof f?r:f).prototype);return c(u,"_invoke",function(n,r,o){var i,u,c,f=0,s=o||[],p=!1,l={p:0,n:0,v:t,a:v,f:v.bind(t,4),d:function(e,n){return i=e,u=0,c=t,l.n=n,a}};function v(n,r){for(u=n,c=r,e=0;!p&&f&&!o&&e<s.length;e++){var o,i=s[e],v=l.p,d=i[2];n>3?(o=d===r)&&(c=i[(u=i[4])?5:(u=3,3)],i[4]=i[5]=t):i[0]<=v&&((o=n<2&&v<i[1])?(u=0,l.v=r,l.n=i[1]):v<d&&(o=n<3||i[0]>r||r>d)&&(i[4]=n,i[5]=r,l.n=d,u=0))}if(o||n>1)return a;throw p=!0,r}return function(o,s,d){if(f>1)throw TypeError("Generator is already running");for(p&&1===s&&v(s,d),u=s,c=d;(e=u<2?t:c)||!p;){i||(u?u<3?(u>1&&(l.n=-1),v(u,c)):l.n=c:l.v=c);try{if(f=2,i){if(u||(o="next"),e=i[o]){if(!(e=e.call(i,c)))throw TypeError("iterator result is not an object");if(!e.done)return e;c=e.value,u<2&&(u=0)}else 1===u&&(e=i.return)&&e.call(i),u<2&&(c=TypeError("The iterator does not provide a '"+o+"' method"),u=1);i=t}else if((e=(p=l.n<0)?c:n.call(r,l))!==a)break}catch(e){i=t,u=1,c=e}finally{f=1}}return{value:e,done:p}}}(n,o,i),!0),u}var a={};function f(){}function s(){}function p(){}e=Object.getPrototypeOf;var l=[][r]?e(e([][r]())):(c(e={},r,function(){return this}),e),v=p.prototype=f.prototype=Object.create(l);function d(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,c(t,o,"GeneratorFunction")),t.prototype=Object.create(v),t}return s.prototype=p,c(v,"constructor",p),c(p,"constructor",s),s.displayName="GeneratorFunction",c(p,o,"GeneratorFunction"),c(v),c(v,o,"Generator"),c(v,r,function(){return this}),c(v,"toString",function(){return"[object Generator]"}),(u=function(){return{w:i,m:d}})()}function c(t,e,n,r){var o=Object.defineProperty;try{o({},"",{})}catch(t){o=0}c=function(t,e,n,r){function i(e,n){c(t,e,function(t){return this._invoke(e,n,t)})}e?o?o(t,e,{value:n,enumerable:!r,configurable:!r,writable:!r}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},c(t,e,n,r)}function a(t,e){return a=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},a(t,e)}function f(t){var e="function"==typeof Map?new Map:void 0;return f=function(t){if(null===t||!function(t){try{return-1!==Function.toString.call(t).indexOf("[native code]")}catch(e){return"function"==typeof t}}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return function(t,e,n){if(i())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,e);var o=new(t.bind.apply(t,r));return n&&a(o,n.prototype),o}(t,arguments,o(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),a(n,t)},f(t)}var s=["children","organisationId","getPermissions"],p=e.createContext(void 0),l="@entur-partner:mount",v="@entur-partner:unmount",d=function(t){function e(){return t.apply(this,arguments)||this}var n,r;return r=t,(n=e).prototype=Object.create(r.prototype),n.prototype.constructor=n,a(n,r),e}(f(CustomEvent));exports.AppProvider=function(t){var o=t.children,i=t.organisationId,c=t.getPermissions,a=function(t,e){if(null==t)return{};var n={};for(var r in t)if({}.hasOwnProperty.call(t,r)){if(-1!==e.indexOf(r))continue;n[r]=t[r]}return n}(t,s),f=e.useState([]),l=f[0],v=f[1];return e.useEffect(function(){function t(){var e;return e=u().m(function t(){return u().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,t.n=1,c();case 1:v(t.v),t.n=3;break;case 2:t.p=2,console.error("Fetching permissions with the provided getPermissions function failed in AppProvider with the following error:",t.v);case 3:return t.a(2)}},t,null,[[0,2]])}),t=function(){var t=this,r=arguments;return new Promise(function(o,i){var u=e.apply(t,r);function c(t){n(u,o,i,c,a,"next",t)}function a(t){n(u,o,i,c,a,"throw",t)}c(void 0)})},t.apply(this,arguments)}!function(){t.apply(this,arguments)}()},[c]),e.createElement(p.Provider,{value:r({},a,{user:r({},a.user,{permissions:l}),activeOrgId:Number(i)})},o)},exports.MOUNT_EVENT_TYPE=l,exports.ROUTE_CHANGE_EVENT_TYPE="@entur-partner:after-route-change",exports.RouteChangeEvent=d,exports.UNMOUNT_EVENT_TYPE=v,exports.createMountEvent=function(t){return new CustomEvent(l,{detail:t})},exports.createUnmountEvent=function(t){return new CustomEvent(v,{detail:t})},exports.registerMicroFrontend=function(t){var e=t.unmount,n=t.microFrontendId,r=t.mount;window.addEventListener(l,function(t){t.detail.id.startsWith(n)&&r(t.detail.mountPoint,t.detail.payload,t.detail.mountPoint)}),window.addEventListener(v,function(t){t.detail.id.startsWith(n)&&e(t.detail.mountPoint)})},exports.useActiveOrgId=function(){var n=e.useContext(p);return t.assertIsDefined(n),n.activeOrgId},exports.useNavigate=function(){var n=e.useContext(p);return t.assertIsDefined(n),n.navigate},exports.useUser=function(){var n=e.useContext(p);return t.assertIsDefined(n),n.user};
|
|
2
2
|
//# sourceMappingURL=micro-frontend.cjs.production.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"micro-frontend.cjs.production.min.js","sources":["../src/AppProvider.tsx","../src/events.ts","../src/registerMicroFrontend.tsx"],"sourcesContent":["import type { Permission } from \"@entur-partner/permission-client-node\";\nimport { assertIsDefined } from \"@entur-partner/util\";\nimport React, {\n\ttype FC,\n\ttype ReactNode,\n\tuseContext,\n\tuseEffect,\n\tuseState,\n} from \"react\";\n\nimport type { User } from \"./User\";\n\ninterface AppContextType {\n\tgetToken: () => Promise<string>;\n\tuser: User;\n\tlogout?: () => void;\n\tactiveOrgId: number;\n\tnavigate: (path: string) => void;\n}\n\nexport const AppContext = React.createContext<AppContextType | undefined>(\n\tundefined,\n);\n\nexport const useUser = () => {\n\tconst context = useContext(AppContext);\n\tassertIsDefined(context);\n\treturn context.user;\n};\n\nexport const useActiveOrgId = () => {\n\tconst context = useContext(AppContext);\n\tassertIsDefined(context);\n\treturn context.activeOrgId;\n};\n\nexport interface AppProviderProps {\n\tchildren: ReactNode;\n\tgetToken: () => Promise<string>;\n\tuser: User;\n\tgetPermissions: () => Promise<Permission[]>;\n\torganisationId: string;\n\tnavigate: (path: string) => void;\n}\n\nexport const useNavigate = () => {\n\tconst context = useContext(AppContext);\n\tassertIsDefined(context);\n\treturn context.navigate;\n};\n\nexport const AppProvider: FC<AppProviderProps> = ({\n\tchildren,\n\torganisationId,\n\tgetPermissions,\n\t...rest\n}) => {\n\tconst [permissions, setPermissions] = useState<Permission[]>([]);\n\n\tuseEffect(() => {\n\t\tasync function fetchData() {\n\t\t\ttry {\n\t\t\t\tconst fetchedPermissions = await getPermissions();\n\t\t\t\tsetPermissions(fetchedPermissions);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t\"Fetching permissions with the provided getPermissions function failed in AppProvider with the following error:\",\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tfetchData();\n\t}, [getPermissions]);\n\n\treturn (\n\t\t<AppContext.Provider\n\t\t\tvalue={{\n\t\t\t\t...rest,\n\t\t\t\tuser: { ...rest.user, permissions: permissions },\n\t\t\t\tactiveOrgId: Number(organisationId),\n\t\t\t}}\n\t\t>\n\t\t\t{children}\n\t\t</AppContext.Provider>\n\t);\n};\n","import type { MicroFrontendPayload } from \"./Payload\";\n\ntype MountEventDetail = {\n\tid: string;\n\tmountPoint: HTMLDivElement;\n\tpayload: MicroFrontendPayload;\n};\n\ntype UnmountEventDetail = {\n\tid: string;\n\tmountPoint: HTMLDivElement;\n};\n\nexport const MOUNT_EVENT_TYPE = \"@entur-partner:mount\";\nexport const UNMOUNT_EVENT_TYPE = \"@entur-partner:unmount\";\n\nexport interface MountEvent extends CustomEvent<MountEventDetail> {}\nexport interface UnmountEvent extends CustomEvent<UnmountEventDetail> {}\n\nexport function createMountEvent(detail: MountEventDetail) {\n\treturn new CustomEvent<MountEventDetail>(MOUNT_EVENT_TYPE, { detail });\n}\n\nexport function createUnmountEvent(detail: UnmountEventDetail) {\n\treturn new CustomEvent<UnmountEventDetail>(UNMOUNT_EVENT_TYPE, { detail });\n}\n\nexport const ROUTE_CHANGE_EVENT_TYPE = \"@entur-partner:after-route-change\";\n\nexport type RouteAction = \"PUSH\" | \"POP\" | \"REPLACE\";\n\ntype RouteChangeEventDetail = {\n\tlocation: Location;\n\taction: RouteAction;\n};\n\nexport class RouteChangeEvent extends CustomEvent<RouteChangeEventDetail> {}\n","/*global EventListener*/\n\nimport {\n\tMOUNT_EVENT_TYPE,\n\ttype MountEvent,\n\tUNMOUNT_EVENT_TYPE,\n\ttype UnmountEvent,\n} from \"./events\";\nimport type { MicroFrontendPayload } from \"./Payload\";\n\ninterface Config {\n\tmicroFrontendId: string;\n\tmount: (\n\t\tmountPoint: HTMLDivElement,\n\t\tpayload: MicroFrontendPayload,\n\t\tdeprecatedMountPoint: HTMLDivElement,\n\t) => void;\n\tunmount: (mountPoint: HTMLDivElement) => void;\n}\n\nexport function registerMicroFrontend(config: Config): void {\n\tconst { unmount, microFrontendId, mount } = config;\n\n\twindow.addEventListener(MOUNT_EVENT_TYPE, ((event: MountEvent) => {\n\t\tif (!event.detail.id.startsWith(microFrontendId)) {\n\t\t\treturn;\n\t\t}\n\t\tmount(\n\t\t\tevent.detail.mountPoint,\n\t\t\tevent.detail.payload,\n\t\t\tevent.detail.mountPoint,\n\t\t);\n\t}) as EventListener);\n\n\twindow.addEventListener(UNMOUNT_EVENT_TYPE, ((event: UnmountEvent) => {\n\t\tif (!event.detail.id.startsWith(microFrontendId)) {\n\t\t\treturn;\n\t\t}\n\t\tunmount(event.detail.mountPoint);\n\t}) as EventListener);\n}\n"],"names":["AppContext","React","createContext","undefined","MOUNT_EVENT_TYPE","UNMOUNT_EVENT_TYPE","RouteChangeEvent","_CustomEvent","apply","this","arguments","_wrapNativeSuper","CustomEvent","_ref","children","organisationId","getPermissions","rest","_objectWithoutPropertiesLoose","_excluded","_useState","useState","permissions","setPermissions","useEffect","_fetchData","
|
|
1
|
+
{"version":3,"file":"micro-frontend.cjs.production.min.js","sources":["../src/AppProvider.tsx","../src/events.ts","../src/registerMicroFrontend.tsx"],"sourcesContent":["import type { Permission } from \"@entur-partner/permission-client-node\";\nimport { assertIsDefined } from \"@entur-partner/util\";\nimport React, {\n\ttype FC,\n\ttype ReactNode,\n\tuseContext,\n\tuseEffect,\n\tuseState,\n} from \"react\";\n\nimport type { User } from \"./User\";\n\ninterface AppContextType {\n\tgetToken: () => Promise<string>;\n\tuser: User;\n\tlogout?: () => void;\n\tactiveOrgId: number;\n\tnavigate: (path: string) => void;\n}\n\nexport const AppContext = React.createContext<AppContextType | undefined>(\n\tundefined,\n);\n\nexport const useUser = () => {\n\tconst context = useContext(AppContext);\n\tassertIsDefined(context);\n\treturn context.user;\n};\n\nexport const useActiveOrgId = () => {\n\tconst context = useContext(AppContext);\n\tassertIsDefined(context);\n\treturn context.activeOrgId;\n};\n\nexport interface AppProviderProps {\n\tchildren: ReactNode;\n\tgetToken: () => Promise<string>;\n\tuser: User;\n\tgetPermissions: () => Promise<Permission[]>;\n\torganisationId: string;\n\tnavigate: (path: string) => void;\n}\n\nexport const useNavigate = () => {\n\tconst context = useContext(AppContext);\n\tassertIsDefined(context);\n\treturn context.navigate;\n};\n\nexport const AppProvider: FC<AppProviderProps> = ({\n\tchildren,\n\torganisationId,\n\tgetPermissions,\n\t...rest\n}) => {\n\tconst [permissions, setPermissions] = useState<Permission[]>([]);\n\n\tuseEffect(() => {\n\t\tasync function fetchData() {\n\t\t\ttry {\n\t\t\t\tconst fetchedPermissions = await getPermissions();\n\t\t\t\tsetPermissions(fetchedPermissions);\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t\"Fetching permissions with the provided getPermissions function failed in AppProvider with the following error:\",\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tfetchData();\n\t}, [getPermissions]);\n\n\treturn (\n\t\t<AppContext.Provider\n\t\t\tvalue={{\n\t\t\t\t...rest,\n\t\t\t\tuser: { ...rest.user, permissions: permissions },\n\t\t\t\tactiveOrgId: Number(organisationId),\n\t\t\t}}\n\t\t>\n\t\t\t{children}\n\t\t</AppContext.Provider>\n\t);\n};\n","import type { MicroFrontendPayload } from \"./Payload\";\n\ntype MountEventDetail = {\n\tid: string;\n\tmountPoint: HTMLDivElement;\n\tpayload: MicroFrontendPayload;\n};\n\ntype UnmountEventDetail = {\n\tid: string;\n\tmountPoint: HTMLDivElement;\n};\n\nexport const MOUNT_EVENT_TYPE = \"@entur-partner:mount\";\nexport const UNMOUNT_EVENT_TYPE = \"@entur-partner:unmount\";\n\nexport interface MountEvent extends CustomEvent<MountEventDetail> {}\nexport interface UnmountEvent extends CustomEvent<UnmountEventDetail> {}\n\nexport function createMountEvent(detail: MountEventDetail) {\n\treturn new CustomEvent<MountEventDetail>(MOUNT_EVENT_TYPE, { detail });\n}\n\nexport function createUnmountEvent(detail: UnmountEventDetail) {\n\treturn new CustomEvent<UnmountEventDetail>(UNMOUNT_EVENT_TYPE, { detail });\n}\n\nexport const ROUTE_CHANGE_EVENT_TYPE = \"@entur-partner:after-route-change\";\n\nexport type RouteAction = \"PUSH\" | \"POP\" | \"REPLACE\";\n\ntype RouteChangeEventDetail = {\n\tlocation: Location;\n\taction: RouteAction;\n};\n\nexport class RouteChangeEvent extends CustomEvent<RouteChangeEventDetail> {}\n","/*global EventListener*/\n\nimport {\n\tMOUNT_EVENT_TYPE,\n\ttype MountEvent,\n\tUNMOUNT_EVENT_TYPE,\n\ttype UnmountEvent,\n} from \"./events\";\nimport type { MicroFrontendPayload } from \"./Payload\";\n\ninterface Config {\n\tmicroFrontendId: string;\n\tmount: (\n\t\tmountPoint: HTMLDivElement,\n\t\tpayload: MicroFrontendPayload,\n\t\tdeprecatedMountPoint: HTMLDivElement,\n\t) => void;\n\tunmount: (mountPoint: HTMLDivElement) => void;\n}\n\nexport function registerMicroFrontend(config: Config): void {\n\tconst { unmount, microFrontendId, mount } = config;\n\n\twindow.addEventListener(MOUNT_EVENT_TYPE, ((event: MountEvent) => {\n\t\tif (!event.detail.id.startsWith(microFrontendId)) {\n\t\t\treturn;\n\t\t}\n\t\tmount(\n\t\t\tevent.detail.mountPoint,\n\t\t\tevent.detail.payload,\n\t\t\tevent.detail.mountPoint,\n\t\t);\n\t}) as EventListener);\n\n\twindow.addEventListener(UNMOUNT_EVENT_TYPE, ((event: UnmountEvent) => {\n\t\tif (!event.detail.id.startsWith(microFrontendId)) {\n\t\t\treturn;\n\t\t}\n\t\tunmount(event.detail.mountPoint);\n\t}) as EventListener);\n}\n"],"names":["AppContext","React","createContext","undefined","MOUNT_EVENT_TYPE","UNMOUNT_EVENT_TYPE","RouteChangeEvent","_CustomEvent","apply","this","arguments","_wrapNativeSuper","CustomEvent","_ref","children","organisationId","getPermissions","rest","_objectWithoutPropertiesLoose","_excluded","_useState","useState","permissions","setPermissions","useEffect","_fetchData","_regenerator","m","_callee","w","_context","p","n","v","console","error","a","fetchData","createElement","Provider","value","_extends","user","activeOrgId","Number","detail","config","unmount","microFrontendId","mount","window","addEventListener","event","id","startsWith","mountPoint","payload","context","useContext","assertIsDefined","navigate"],"mappings":"0lHAoBaA,EAAaC,EAAMC,mBAC/BC,GCRYC,EAAmB,uBACnBC,EAAqB,yBAsBrBC,WAAiBC,GAAA,SAAAD,IAAA,OAAAC,EAAAC,MAAAC,KAAAC,YAAAD,IAAA,SAAA,SAAAF,KAAAD,yEAAAA,CAAA,EAAAK,EAAQC,kCDeW,SAAzBC,GAKnB,IAJJC,EAAQD,EAARC,SACAC,EAAcF,EAAdE,eACAC,EAAcH,EAAdG,eACGC,6IAAIC,CAAAL,EAAAM,GAEPC,EAAsCC,EAAQA,SAAe,IAAtDC,EAAWF,EAAA,GAAE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