From cf5354554ca008521e7d35e3b5352a2d8b72a0f6 Mon Sep 17 00:00:00 2001 From: emielvdveen Date: Fri, 8 Dec 2023 00:05:22 +0100 Subject: [PATCH 1/3] Added locale as parameter and renamed Storage to Bridge --- README.md | 8 +++---- public/port-0.0.0-py3-none-any.whl | Bin 6497 -> 6502 bytes src/{fake_storage.ts => fake_bridge.ts} | 4 ++-- src/framework/assembly.ts | 6 ++--- src/framework/command_router.ts | 10 ++++----- .../py/dist/port-0.0.0-py3-none-any.whl | Bin 6497 -> 6502 bytes src/framework/types/modules.ts | 2 +- src/index.tsx | 21 +++++++++--------- src/{live_storage.ts => live_bridge.ts} | 15 +++++++------ 9 files changed, 33 insertions(+), 33 deletions(-) rename src/{fake_storage.ts => fake_bridge.ts} (82%) rename src/{live_storage.ts => live_bridge.ts} (68%) diff --git a/README.md b/README.md index 10c3365e..a88d6b28 100644 --- a/README.md +++ b/README.md @@ -283,7 +283,7 @@ Port uses the following data model (also see: [src/framework/types](src/framewor | ProcessingEngine | Responsible for processing donation flows | | VisualizationEngine | Responsible for presenting the UI and accepting user input | | CommandHandler | Decoupling of ProcessingEngine and VisualizationEngine | - | Storage | Callback interface for Storage Commands (e.g. Donation) | + | Bridge | Callback interface for Bridge Commands (e.g. Donation) | - [Pages](src/framework/types/pages.ts) @@ -345,7 +345,7 @@ See: [src/framework/processing/py/port](src/framework/processing/py/port) - [API](src/framework/processing/py/port/api) - - [commands.py](src/framework/processing/py/port/api/commands.py): Defines commands, pages and prompts that are used to communicate from the Python script to the `VisualisationEngine` and `Storage`. + - [commands.py](src/framework/processing/py/port/api/commands.py): Defines commands, pages and prompts that are used to communicate from the Python script to the `VisualisationEngine` and `Bridge`. - [props.py](src/framework/processing/py/port/api/commands.py): Defines property objects for pages and prompts ## Code instructions @@ -542,7 +542,7 @@ Change implementation of [assembly.ts](src/framework/assembly.ts) to support you ```Typescript import MyEngine from './visualisation/my/engine' import WorkerProcessingEngine from './processing/worker_engine' -import { VisualisationEngine, ProcessingEngine, Storage } from './types/modules' +import { VisualisationEngine, ProcessingEngine, Bridge } from './types/modules' import CommandRouter from './command_router' export default class Assembly { @@ -550,7 +550,7 @@ export default class Assembly { processingEngine: ProcessingEngine router: CommandRouter - constructor (worker: Worker, system: Storage) { + constructor (worker: Worker, bridge: Bridge) { const sessionId = String(Date.now()) this.visualisationEngine = new MyEngine() this.router = new CommandRouter(system, this.visualisationEngine) diff --git a/public/port-0.0.0-py3-none-any.whl b/public/port-0.0.0-py3-none-any.whl index c4593e28e8ea555243361dcd876ebd09f3e238d2..7985b9abed8645f7f3b13f4b5851899bd90a8dd8 100644 GIT binary patch delta 911 zcmaE8^vq~OzcAk#28MrE85kIf85tO487AvVir4$PhB&%7hB!{0aM16t0Z-feN-lZF zsKr~Gy|?)KOu5~rHKA;~)#S+RNe`De*H+uKJh1th^z(P_|8IR2^!#4Vu_B*G4^$0! z3l4Iy3*8W|KN=qr=pZLEA#}x?MK3zl9B-?CcAKxv{dCprkkxY6R=2Kwee;v!TpRuw z#`Oj-fA~!j=V@HruIpwW=WDt4|CiX!N7q)}Ew1+doWJvF%$L?Gk+dDr>$84aM4Oe> zKBWL;5>`qPsZ88EaythM)k!M0OB?O-U2 zzJdnx>=3q6Ayy#{txsQqV{K#K9;wLUfL z=XwVW7rJP?&9@Jv;|`s3OIYsFaC6Z~ zR@0Kc>rZy(tX89XQq35$zUEewFxwBl;`YHb|&O)o+PdzU!E=+qq zyXE@RduHBzDklTB=&y2IQXACuyF^PcWW((5(~ITK8~XWZuT_edK2*O)deMa6Tdj7i z%42l>Dc>1xn|OG#(8+TJ??u*UtBM`Ei{gQ zPuy=~<`cWVNS$RqA6?h|@71-XOElH%4oB2?c-$9diV1DIv-DCbN*Ai}C0;LXS+!VFJg ekcb9mu5u;@25DdlgMlTCa+7r>_1ON3fkXf&hm)QF delta 906 zcmaE6^w4NSzc8QGwX;_*GB7YWFfuU6GE80|Azwdrf@3z5BTwu5&)P+69`LQ(Hr;XQ zqpHoRnFp&Q9!u;pUOY4M^uOQ7f^HR`RDDu?vieCYm)ypLQiYRq7B%l&dsdsRsK7Jm z%=?PR^-5Gt=LvYTwi+ ztj-T!B=%qA{~qA?{C@TKypQpFfBpGsKBxPivv5*d``1<5{4YPfb589UcYrrDiwMw@ z96+qdkhwB+QYerW0mM=uFN^1fd$_v#@SbwyYETehy|8!r2PR?H?gQK|yE|5FJ-VD_ zW@n)IJ-h4g=jsc*Y*?o7=FNq#X>885Vx`}NQ`VMrFS>Z8K=|Yqm8fo|w$nG)u%>?F$`^%<&sqhPfD2_+F%tUJ5;$~rxx;#2Rp z1{&>fmK9j|DgENMh5Z6snD#riF`qwdqwZ>D+SvWL@`+f;p=~dwmy506w02pFY(nHr z@%j~96Ms40DcE#S4}rI@m<=Iw^)F~=67*x*?^;_%rZ>rXotTW34&PHfI+QIxl?1Sa3 zTgzVl?>g>UsL$;DO3iNf+cn95qYk7ry}S3#DeYgy)gTy%J6`sL2PIhM-_cW3LD(F->NY6qNx-G%!n*Gchno!&Ct2C5%#{ OU`1Y%Vr)OeKr#RX7o1)I diff --git a/src/fake_storage.ts b/src/fake_bridge.ts similarity index 82% rename from src/fake_storage.ts rename to src/fake_bridge.ts index 605be9b0..104cc57f 100644 --- a/src/fake_storage.ts +++ b/src/fake_bridge.ts @@ -1,7 +1,7 @@ import { CommandSystem, CommandSystemDonate, isCommandSystemDonate } from './framework/types/commands' -import { Storage } from './framework/types/modules' +import { Bridge } from './framework/types/modules' -export default class FakeStorage implements Storage { +export default class FakeBridge implements Bridge { send (command: CommandSystem): void { if (isCommandSystemDonate(command)) { this.handleDonation(command) diff --git a/src/framework/assembly.ts b/src/framework/assembly.ts index 8a02ec7c..a121b62d 100644 --- a/src/framework/assembly.ts +++ b/src/framework/assembly.ts @@ -1,7 +1,7 @@ import ReactEngine from './visualisation/react/engine' import ReactFactory from './visualisation/react/factory' import WorkerProcessingEngine from './processing/worker_engine' -import { VisualisationEngine, ProcessingEngine, Storage } from './types/modules' +import { VisualisationEngine, ProcessingEngine, Bridge } from './types/modules' import CommandRouter from './command_router' export default class Assembly { @@ -9,10 +9,10 @@ export default class Assembly { processingEngine: ProcessingEngine router: CommandRouter - constructor (worker: Worker, system: Storage) { + constructor (worker: Worker, bridge: Bridge) { const sessionId = String(Date.now()) this.visualisationEngine = new ReactEngine(new ReactFactory()) - this.router = new CommandRouter(system, this.visualisationEngine) + this.router = new CommandRouter(bridge, this.visualisationEngine) this.processingEngine = new WorkerProcessingEngine(sessionId, worker, this.router) } } diff --git a/src/framework/command_router.ts b/src/framework/command_router.ts index efe0de58..e3c51145 100644 --- a/src/framework/command_router.ts +++ b/src/framework/command_router.ts @@ -1,12 +1,12 @@ import { Command, Response, isCommandSystem, isCommandUI, CommandUI, CommandSystem } from './types/commands' -import { CommandHandler, Storage, VisualisationEngine } from './types/modules' +import { CommandHandler, Bridge, VisualisationEngine } from './types/modules' export default class CommandRouter implements CommandHandler { - system: Storage + bridge: Bridge visualisationEngine: VisualisationEngine - constructor (system: Storage, visualisationEngine: VisualisationEngine) { - this.system = system + constructor (bridge: Bridge, visualisationEngine: VisualisationEngine) { + this.bridge = bridge this.visualisationEngine = visualisationEngine } @@ -23,7 +23,7 @@ export default class CommandRouter implements CommandHandler { } onCommandSystem (command: CommandSystem, resolve: (response: Response) => void): void { - this.system.send(command) + this.bridge.send(command) resolve({ __type__: 'Response', command, payload: { __type__: 'PayloadVoid', value: undefined } }) } diff --git a/src/framework/processing/py/dist/port-0.0.0-py3-none-any.whl b/src/framework/processing/py/dist/port-0.0.0-py3-none-any.whl index c4593e28e8ea555243361dcd876ebd09f3e238d2..7985b9abed8645f7f3b13f4b5851899bd90a8dd8 100644 GIT binary patch delta 911 zcmaE8^vq~OzcAk#28MrE85kIf85tO487AvVir4$PhB&%7hB!{0aM16t0Z-feN-lZF zsKr~Gy|?)KOu5~rHKA;~)#S+RNe`De*H+uKJh1th^z(P_|8IR2^!#4Vu_B*G4^$0! z3l4Iy3*8W|KN=qr=pZLEA#}x?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J6`sL2PIhM-_cW3LD(F->NY6qNx-G%!n*Gchno!&Ct2C5%#{ OU`1Y%Vr)OeKr#RX7o1)I diff --git a/src/framework/types/modules.ts b/src/framework/types/modules.ts index ccf10358..f460b30d 100644 --- a/src/framework/types/modules.ts +++ b/src/framework/types/modules.ts @@ -12,7 +12,7 @@ export interface VisualisationEngine { terminate: () => void } -export interface Storage { +export interface Bridge { send: (command: CommandSystem) => void } diff --git a/src/index.tsx b/src/index.tsx index acf5e1b9..2aef6ce7 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,30 +1,29 @@ import './fonts.css' import './framework/styles.css' import Assembly from './framework/assembly' -import { Storage } from './framework/types/modules' -import LiveStorage from './live_storage' -import FakeStorage from './fake_storage' +import { Bridge } from './framework/types/modules' +import LiveBridge from './live_bridge' +import FakeBridge from './fake_bridge' const rootElement = document.getElementById('root') as HTMLElement -const locale = 'en' const workerFile = new URL('./framework/processing/py_worker.js', import.meta.url) const worker = new Worker(workerFile) let assembly: Assembly -const run = (system: Storage): void => { - assembly = new Assembly(worker, system) +const run = (bridge: Bridge, locale: string): void => { + assembly = new Assembly(worker, bridge) assembly.visualisationEngine.start(rootElement, locale) assembly.processingEngine.start() } -if (process.env.REACT_APP_BUILD!=='standalone' && process.env.NODE_ENV === 'production') { +if (process.env.REACT_APP_BUILD !== 'standalone' && process.env.NODE_ENV === 'production') { // Setup embedded mode (requires to be embedded in iFrame) - console.log('Initializing storage system') - LiveStorage.create(window, run) + console.log('Initializing bridge system') + LiveBridge.create(window, run) } else { // Setup local development mode - console.log('Running with fake storage') - run(new FakeStorage()) + console.log('Running with fake bridge') + run(new FakeBridge(), 'en') } diff --git a/src/live_storage.ts b/src/live_bridge.ts similarity index 68% rename from src/live_storage.ts rename to src/live_bridge.ts index c1f05d4b..1133baab 100644 --- a/src/live_storage.ts +++ b/src/live_bridge.ts @@ -1,22 +1,23 @@ import { CommandSystem, CommandSystemDonate, isCommandSystemDonate } from './framework/types/commands' -import { Storage } from './framework/types/modules' +import { Bridge } from './framework/types/modules' -export default class LiveStorage implements Storage { +export default class LiveBridge implements Bridge { port: MessagePort constructor (port: MessagePort) { this.port = port } - static create (window: Window, callback: (system: Storage) => void): void { + static create (window: Window, callback: (bridge: Bridge, locale: string) => void): void { window.addEventListener('message', (event) => { console.log('MESSAGE RECEIVED', event) // Skip webpack messages - if (event.ports.length === 0) { - return + if (event.data.action === 'live-init') { + const bridge = new LiveBridge(event.ports[0]) + const locale = event.data.locale + console.log('LOCALE', locale) + callback(bridge, locale) } - const system = new LiveStorage(event.ports[0]) - callback(system) }) } From f3f35f0370642bd1c09451b169d54ccd8b3778b4 Mon Sep 17 00:00:00 2001 From: emielvdveen Date: Fri, 8 Dec 2023 00:22:46 +0100 Subject: [PATCH 2/3] Added CommandSystemExit --- public/port-0.0.0-py3-none-any.whl | Bin 6502 -> 6593 bytes src/fake_bridge.ts | 12 +++++++++--- .../py/dist/port-0.0.0-py3-none-any.whl | Bin 6502 -> 6593 bytes .../processing/py/port/api/commands.py | 15 +++++++++++++++ src/framework/processing/py/port/script.py | 6 +++++- src/framework/types/commands.ts | 14 ++++++++++++-- src/live_bridge.ts | 8 ++------ 7 files changed, 43 insertions(+), 12 deletions(-) diff --git a/public/port-0.0.0-py3-none-any.whl b/public/port-0.0.0-py3-none-any.whl index 7985b9abed8645f7f3b13f4b5851899bd90a8dd8..dc81166b500a818137b7c34bd9e282e882bf0a59 100644 GIT binary patch delta 2602 zcmV+_3f1-IGQl&Dp$Z(+y*3d6005u^k*gYiwUEI|#4r$s?|F)llM7`ZK=9;x@T%-d zWGKyaiMGkoj9?Mp-I-Kk8oJ;?bLi0d|4HWmx}l9x--dB)y*=JPptm?(E6oQW4uK+o zzR~8~p3tb&x7f4hyd!|Ch(q6KQFqIf9BJ;Q$CFZi<|rIoM`^0?Tkf&-<8#${G5|Dx zpAo=3%L>(!rZT4u#h72;f4{cN&I##l@@YUR)s@*F=SVmnf^P{o^1tG28f{);@DOQo z{&blJdmCLiY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ge.ts index 104cc57f..d930f8c3 100644 --- a/src/fake_bridge.ts +++ b/src/fake_bridge.ts @@ -1,16 +1,22 @@ -import { CommandSystem, CommandSystemDonate, isCommandSystemDonate } from './framework/types/commands' +import { CommandSystem, CommandSystemDonate, CommandSystemExit, isCommandSystemDonate, isCommandSystemExit } from './framework/types/commands' import { Bridge } from './framework/types/modules' export default class FakeBridge implements Bridge { send (command: CommandSystem): void { if (isCommandSystemDonate(command)) { this.handleDonation(command) + } else if (isCommandSystemExit(command)) { + this.handleExit(command) } else { - console.log('[LocalSystem] received unknown command: ' + JSON.stringify(command)) + console.log('[FakeBridge] received unknown command: ' + JSON.stringify(command)) } } handleDonation (command: CommandSystemDonate): void { - console.log(`[LocalSystem] received donation: ${command.key}=${command.json_string}`) + console.log(`[FakeBridge] received donation: ${command.key}=${command.json_string}`) + } + + handleExit (command: CommandSystemExit): void { + console.log(`[FakeBridge] received exit: ${command.code}=${command.info}`) } } diff --git a/src/framework/processing/py/dist/port-0.0.0-py3-none-any.whl b/src/framework/processing/py/dist/port-0.0.0-py3-none-any.whl index 7985b9abed8645f7f3b13f4b5851899bd90a8dd8..dc81166b500a818137b7c34bd9e282e882bf0a59 100644 GIT binary patch delta 2602 zcmV+_3f1-IGQl&Dp$Z(+y*3d6005u^k*gYiwUEI|#4r$s?|F)llM7`ZK=9;x@T%-d zWGKyaiMGkoj9?Mp-I-Kk8oJ;?bLi0d|4HWmx}l9x--dB)y*=JPptm?(E6oQW4uK+o zzR~8~p3tb&x7f4hyd!|Ch(q6KQFqIf9BJ;Q$CFZi<|rIoM`^0?Tkf&-<8#${G5|Dx zpAo=3%L>(!rZT4u#h72;f4{cN&I##l@@YUR)s@*F=SVmnf^P{o^1tG28f{);@DOQo z{&blJdmCLiYcj0!mHb_|iwTyCzdyxS=ByD)$V{-@Z;{LJ*;elPYs`1=jy527!J<%h zz7Lo2imTD$slkfE_efa_VrD_gKfsg|G&RZ;B|}CN_8zN}i|V;}OH_UO=9*)PL!W zv*>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gtg)}EuQB5TJrc|ejK2c$E zXvqCuPuq|UnuxmCQov7fwOl$^q7L5?rxWd2$2gDcax-ddleMnJ)XkD<_1CrQ4$46$ zQa0M?w#k`wEPBKzE>ok%S5Eu&j9s<1T(>pGHNhLeKIWsrcG9>{CjE*s@(pu1WAZPv z+!Lz-1jmWa*OQACCx30w%aWon0EOXwKTGHaxi4nHRRk{}C#&@jP}C^grp?{gzxMDI7Ty7`?cH#){Z7S=Ptl8p+qR{Yde~Yg4oE44i~$d zlRs?C`rr;!`Hg)th>=&6qPt$g&PHITNPyX*$ptlZj@RV4y?-?7dd0%LoXa@9`a2;0 zNEK}w)E@Ygbepb@c9N*BDk8!f8w&|9Hcki2JZNe|IKo@&o(0Si2byU9Sgfb)84~B4 zB}MK+yxgZLJLM0$32{1&@{H*?(3a<$gxBTXHcJj9$xyT}szIcEQi}U@DiKt$oA;M< z9?vmOOe?J-Uw<3Iyc?pB`?Wf_s%`;A`5%c_Jz>L>63NbR@00Ohw)--XBg2y)@x~C> zGclc}znrEfs`N+PZxf&@($^J1eE-~m@IfH$iGHlS%yO;F`c@agjK$HAyFR}WE3-SR zrhSc-uG^1ue-*Y>UJtxp`!fT`y7U^&1J7H2i~j1?r75H-e#2OQh)CZR0$f#w+^f^Y zF1b_0jlS$fn|BH@jMw1Sb2eKSfVY2>SQn5Ak@Xdy*8l(jVFHu#7g7P7lSLRlJERK$ z0B~<|bT4gTX>KlXc~DCM0u%!j000080000X0E2Pdrl$q~04Nmz01f~E0000000000 z0HlGglfD=`0)Z2gju{t|4-^QK8W}1Akrb1T85ffu6$L9$O928D0~7!N00;m803k@n oiO$!i0RRAZ0ssIT00000000000001_0Unc$87>C>761SM0IDX((EtDd diff --git a/src/framework/processing/py/port/api/commands.py b/src/framework/processing/py/port/api/commands.py index 3bcb4cc5..e7c11188 100644 --- a/src/framework/processing/py/port/api/commands.py +++ b/src/framework/processing/py/port/api/commands.py @@ -24,3 +24,18 @@ def toDict(self): dict["key"] = self.key dict["json_string"] = self.json_string return dict + + +class CommandSystemExit: + __slots__ = "code", "info" + + def __init__(self, code, info): + self.code = code + self.info = info + + def toDict(self): + dict = {} + dict["__type__"] = "CommandSystemExit" + dict["code"] = self.code + dict["info"] = self.info + return dict diff --git a/src/framework/processing/py/port/script.py b/src/framework/processing/py/port/script.py index 7abb7d71..35386d7d 100644 --- a/src/framework/processing/py/port/script.py +++ b/src/framework/processing/py/port/script.py @@ -1,5 +1,5 @@ import port.api.props as props -from port.api.commands import (CommandSystemDonate, CommandUIRender) +from port.api.commands import (CommandSystemDonate, CommandSystemExit, CommandUIRender) import pandas as pd import zipfile @@ -58,6 +58,7 @@ def process(sessionId): meta_data.append(("debug", f"{platform}: donate consent data")) yield donate(f"{sessionId}-{platform}", consent_result.value) + yield exit(0, "Success") yield render_end_page() @@ -141,3 +142,6 @@ def prompt_consent(id, data, meta_data): def donate(key, json_string): return CommandSystemDonate(key, json_string) + +def exit(code, info): + return CommandSystemExit(code, info) diff --git a/src/framework/types/commands.ts b/src/framework/types/commands.ts index f8ff58a0..096e28f4 100644 --- a/src/framework/types/commands.ts +++ b/src/framework/types/commands.ts @@ -82,10 +82,11 @@ export function isCommand (arg: any): arg is Command { } export type CommandSystem = - CommandSystemDonate + CommandSystemDonate | + CommandSystemExit export function isCommandSystem (arg: any): arg is CommandSystem { - return isCommandSystemDonate(arg) + return isCommandSystemDonate(arg) || isCommandSystemExit(arg) } export type CommandUI = @@ -104,6 +105,15 @@ export function isCommandSystemDonate (arg: any): arg is CommandSystemDonate { return isInstanceOf(arg, 'CommandSystemDonate', ['key', 'json_string']) } +export interface CommandSystemExit { + __type__: 'CommandSystemExit' + code: number + info: string +} +export function isCommandSystemExit (arg: any): arg is CommandSystemExit { + return isInstanceOf(arg, 'CommandSystemExit', ['code', 'info']) +} + export interface CommandUIRender { __type__: 'CommandUIRender' page: PropsUIPage diff --git a/src/live_bridge.ts b/src/live_bridge.ts index 1133baab..4aa16d4d 100644 --- a/src/live_bridge.ts +++ b/src/live_bridge.ts @@ -1,4 +1,4 @@ -import { CommandSystem, CommandSystemDonate, isCommandSystemDonate } from './framework/types/commands' +import { CommandSystem, isCommandSystem } from './framework/types/commands' import { Bridge } from './framework/types/modules' export default class LiveBridge implements Bridge { @@ -22,17 +22,13 @@ export default class LiveBridge implements Bridge { } send (command: CommandSystem): void { - if (isCommandSystemDonate(command)) { + if (isCommandSystem(command)) { this.port.postMessage(command) } else { this.log('error', 'received unknown command', command) } } - handleDonation (command: CommandSystemDonate): void { - this.log('info', `received donation: ${command.key}=${command.json_string}`) - } - private log (level: 'info' | 'error', ...message: any[]): void { const logger = level === 'info' ? console.log : console.error logger(`[${this.constructor.name}]`, ...message) From c9c192d197c5fb232e39f0a2dd634bbde66b64bb Mon Sep 17 00:00:00 2001 From: emielvdveen Date: Fri, 8 Dec 2023 01:36:32 +0100 Subject: [PATCH 3/3] Added resize observer --- src/index.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/index.tsx b/src/index.tsx index 2aef6ce7..af027173 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -27,3 +27,11 @@ if (process.env.REACT_APP_BUILD !== 'standalone' && process.env.NODE_ENV === 'pr console.log('Running with fake bridge') run(new FakeBridge(), 'en') } + +const observer = new ResizeObserver(() => { + const height = window.document.body.scrollHeight; + const action = "resize" + window.parent.postMessage({action, height}, "*") +}); + +observer.observe(window.document.body);