Skip to content

Added support for App V2#2

Merged
ErwinSpierings merged 6 commits into
mainfrom
BB-3108-Support-apphooks-in-app
May 11, 2026
Merged

Added support for App V2#2
ErwinSpierings merged 6 commits into
mainfrom
BB-3108-Support-apphooks-in-app

Conversation

@remcoanker

Copy link
Copy Markdown
Member

Added responses
Added routes

Added responses
Added routes
@remcoanker remcoanker requested a review from a team as a code owner May 8, 2026 10:14
@ErwinSpierings ErwinSpierings requested a review from Copilot May 11, 2026 06:36
@ErwinSpierings

Copy link
Copy Markdown
Member

@copilot review

Copilot AI commented May 11, 2026

Copy link
Copy Markdown

@copilot review

Review complete. Found one bug: customer and customerlist routes in src/routes.js were mapped to user_group/:uuid / user_group paths instead of customer/:uuid / customer. Fixed in 10d3096 — 4 previously failing tests now pass (69/69 total). No other issues found; CodeQL and ESLint clean.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the SDK to support “App V2” style navigation by introducing a named-route navigation API (navigate.push/replace/back), expanding the route map, and adding request/response correlation (via _id) for postMessage-based hosts.

Changes:

  • Reworked navigation API to push/replace/back and expanded src/routes.js for the app (V2) route set.
  • Added _id correlation + Promise-based responses in sendToApp, plus a Flutter bridge path via flutter_inappwebview.
  • Updated Jest tests and README to cover the new navigation and messaging behavior; bumped package version.

Reviewed changes

Copilot reviewed 8 out of 10 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
test/navigate.test.js Adds table-driven tests for V2 route building and new navigation methods.
test/index.test.js Updates sendToApp tests for correlation IDs, Promise replies, and Flutter bridge path.
src/routes.js Introduces/updates route mappings for app (V2).
src/navigate.js Replaces old navigation helpers with push/replace/back using route substitution.
src/index.js Adds Promise correlation for postMessage replies and flutter_inappwebview support.
README.md Documents the new navigation API and available routes.
package.json Bumps package version.
package-lock.json Updates lockfile version metadata to match package version.
eslint.config.mjs Adds Jest/Node globals for tests and config files.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/index.js
Comment on lines +71 to +80
window.addEventListener("message", function (e) {
const data = e.data;

// Modern request/response: resolve the matching pending request.
if (data && typeof data === 'object' && typeof data._id === 'string' && pendingRequests.has(data._id)) {
const resolve = pendingRequests.get(data._id);
pendingRequests.delete(data._id);
resolve(data.result);
return;
}
Comment thread src/index.js
Comment on lines +48 to +67
const id = generateRequestId();
message._id = id;

const promise = new Promise((resolve) => {
const timeout = setTimeout(() => {
if (pendingRequests.has(id)) {
pendingRequests.delete(id);
resolve(undefined);
}
}, REQUEST_TIMEOUT_MS);

pendingRequests.set(id, (response) => {
clearTimeout(timeout);
resolve(response);
});
});

target.postMessage(message, "*");

return promise;
Comment thread src/routes.js
Comment on lines +30 to 32
'usergroup': 'user_group/:uuid',
'usergrouplist': 'user_group',

Comment thread src/navigate.js
Comment on lines 27 to 38
export default {
navigate: function(route, params) {
push: function(route, params) {
return sendToApp("navigate", getRoute(route, params));
},

back: function() {
return sendToApp("back");
},

/**
* @param newsId string | number legacy apps use ID's the other ones use UUID's
* @param replace boolean When setting replace to true the current view will be replaced with the new view
*/
news: function(newsId, replace = false) {
return this.navigate('news', { id: newsId, replace: replace });
replace: function(route, params) {
return sendToApp("navigate", {...getRoute(route, params), replace: true});
},

/**
* @param categoryId string | number legacy apps use ID's the other ones use UUID's
* @param replace boolean When setting replace to true the current view will be replaced with the new view
*/
newslist: function(categoryId, replace = false) {
return this.navigate('newslist', { id: categoryId, replace: replace });
back: function() {
return sendToApp("back");
},
Comment thread package.json Outdated
{
"name": "@bundeling/app-sdk",
"version": "1.0.5",
"version": "1.0.6",
Comment thread test/index.test.js
Comment on lines +17 to 26
test('sendToApp should post a message with a correlation id', () => {
window.parent.postMessage = jest.fn();
sdk.sendToApp('test', { data: 'data' });
expect(window.parent.postMessage).toHaveBeenCalledWith(message, originTarget);

expect(window.parent.postMessage).toHaveBeenCalledTimes(1);
const [message, targetOrigin] = window.parent.postMessage.mock.calls[0];
expect(targetOrigin).toBe('*');
expect(message).toEqual(expect.objectContaining({ type: 'test', data: 'data' }));
expect(typeof message._id).toBe('string');
});
Comment thread test/navigate.test.js Outdated
Comment on lines +22 to +23
['customer', { uuid: 'abc' }, 'customer/abc'],
['customerlist', {}, 'customer'],
Comment thread test/navigate.test.js
Comment on lines +52 to +56
describe('push', () => {
test.each(routeCases)('push(%s) routes to %s', (route, params, expected) => {
navigate.push(route, params);
expectPosted({ type: 'navigate', route: expected, params: params });
});
Comment thread README.md Outdated
Comment on lines +51 to +52
| alert | message: string, title?: string | Displays an alert dialog with a message and an optional title. |
| toast | message: string | Displays a toast message at the bottom of the screen. |
Comment thread README.md
Comment on lines +73 to +82
| Route | Path | Required params |
|---------------------|-----------------------------------|-----------------|
| user | user/:uuid | uuid |
| userlist | user | - |
| customer | customer/:uuid | uuid |
| customerlist | customer | - |
| news | news/:uuid | uuid |
| newslist | news | - |
| event | event/:uuid | uuid |
| eventlist | event | - |
@remcoanker remcoanker force-pushed the BB-3108-Support-apphooks-in-app branch from 10d3096 to 486ef4a Compare May 11, 2026 06:49
@ErwinSpierings ErwinSpierings merged commit fb27d4c into main May 11, 2026
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants