I am creating an experimental confluence app with forge where multiple components on multiple pages within a space have to interact. They will exchange (limited amounts of) data via the storage API.
It would be nice if I can somehow have a function run when the app loads for the first time. That way, I can have a single place where I make sure some basics are set up in app storage. As it is now, every component render function calls a ‘storage init’ function which checks if init is necessary, but it is still overkill.
When you say “when the app loads for the first time”, I think it might be more appropriate to think in terms of a per-tenant context here so you should be able to register for installation events. Here is some code to get you started:
trigger:
- key: dl-spike-one-trigger-appinstalled
function: dl-trigger-appinstalled
events:
- avi:forge:installed:app
- avi:forge:upgraded:app
function:
- key: dl-trigger-appinstalled
handler: index.dl_handleTriggerAppInstalled
permissions:
scopes:
- read:confluence-content.summary
- read:confluence-content.all
- read:page:confluence
- storage:app
- read:space:confluence
export async function dl_handleTriggerAppInstalled( event, context) {
console.log( `dl_handleTriggerAppInstalled`);
console.log(`All info about my context: ${JSON.stringify(context, null, 2)}`);
console.log(`All info about my event: ${JSON.stringify(event, null, 2)}`);
};
Not on logging in and loading anything from a space for the first time (which is what I am looking for and which I don't think this does), nor on `forge deploy` and `forge install --upgrade`
My app uses storage and before any component does anything (rendering, macro config) I want to run some logic to make sure the data in Storage is OK. A I understand it, the app storage scope is per-space, so I need an event per-space.
I tested my app and did get the avi:forge:installed:app event after the app was installed in a site since I was able to see my console.log(Oh wow, I’ve been installed:) log after installing by running forge logs. Did you try testing if you get the avi:forge:installed:app event after running forge install rather than forge install --upgrade?
The app gets storage scoped to it’s installation rather than a separate storage area per space.