Skip to content

feat(powerbi): migrate to TypeScript and fix embed-token refresh#816

Open
rusko124 wants to merge 2 commits into
masterfrom
feat/migrate-powerbi-ts
Open

feat(powerbi): migrate to TypeScript and fix embed-token refresh#816
rusko124 wants to merge 2 commits into
masterfrom
feat/migrate-powerbi-ts

Conversation

@rusko124

@rusko124 rusko124 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

PR Type

Enhancement, Bug fix, Tests


Description

  • Migrates Power BI app to TypeScript

  • Adds expiration-aware token refresh

  • Adds service and utility unit tests

  • Uses Edge Apps build tooling


Diagram Walkthrough

flowchart LR
  legacy["Legacy static JavaScript"]
  ts["TypeScript source modules"]
  token["Expiration-aware token refresh"]
  tests["Bun unit tests"]
  build["Edge Apps build pipeline"]
  legacy -- "migrated to" --> ts
  ts -- "adds" --> token
  ts -- "covered by" --> tests
  ts -- "built with" --> build
Loading

File Walkthrough

Relevant files
Enhancement
9 files
globals.d.ts
Add Screenly settings global TypeScript definitions           
+17/-0   
main.ts
Add TypeScript app entrypoint and panic setup                       
+16/-0   
services.lib.ts
Extract embed service and error rendering helpers               
+50/-0   
services.ts
Implement token retrieval, embedding, and refresh               
+126/-0 
services.types.ts
Add shared Power BI service interfaces                                     
+11/-0   
utils.lib.ts
Define refresh and backoff timing constants                           
+8/-0     
utils.ts
Add refresh timing and embed type utilities                           
+62/-0   
style.css
Add app layout and error view styles                                         
[link]   
index.html
Load TypeScript module instead of static scripts                 
+2/-4     
Tests
2 files
services.test.ts
Add Power BI service unit coverage                                             
+292/-0 
utils.test.ts
Add utility timing and URL tests                                                 
+140/-0 
Miscellaneous
1 files
main.js
Remove legacy vanilla JavaScript implementation                   
+0/-180 
Configuration changes
2 files
package.json
Switch scripts to Edge Apps toolchain                                       
+16/-10 
tsconfig.json
Add TypeScript configuration for source build                       
+8/-0     

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 migrates the Power BI edge app from a static “vanilla JS + vendor copies” setup to a TypeScript + @screenly/edge-apps build pipeline, and updates the embed-token refresh logic to reschedule refreshes based on token expiration with exponential backoff on failures.

Changes:

  • Replaces static/js/main.js with a TypeScript entrypoint (src/main.ts) and moves core logic into typed service/util modules.
  • Fixes token refresh scheduling by using the embed token expiration (plus a capped interval) and adds exponential backoff for refresh failures.
  • Introduces unit tests (Bun + happy-dom) for refresh timing utilities and Power BI service behavior; updates build/test/lint scripts accordingly.

Reviewed changes

Copilot reviewed 13 out of 18 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
edge-apps/powerbi/tsconfig.json Adds TS config extending the shared edge-apps config.
edge-apps/powerbi/static/js/vendor/panic-overlay.min.js Removes vendored panic-overlay bundle (now imported via bundler).
edge-apps/powerbi/static/js/main.js Removes legacy JS entrypoint (replaced by TS modules).
edge-apps/powerbi/src/utils.ts Adds refresh-interval, refresh-delay, backoff, and embed-type utilities.
edge-apps/powerbi/src/utils.test.ts Adds Bun unit tests for utility timing/type helpers.
edge-apps/powerbi/src/utils.lib.ts Adds constants for refresh/backoff timing behavior.
edge-apps/powerbi/src/services.types.ts Introduces typed contracts for token and error payloads.
edge-apps/powerbi/src/services.ts Adds typed token fetching, refresh loop, and embed initialization logic.
edge-apps/powerbi/src/services.test.ts Adds tests for token fetch, refresh loop scheduling, embed init, and error rendering.
edge-apps/powerbi/src/services.lib.ts Adds embed service singleton + shared error rendering helper.
edge-apps/powerbi/src/main.ts New TS entrypoint wiring panic-overlay + initialization.
edge-apps/powerbi/src/globals.d.ts Adds global screenly typings for the app.
edge-apps/powerbi/src/css/style.css Moves styles into the bundler pipeline and adds error UI styling.
edge-apps/powerbi/package.json Switches to edge-apps-scripts build/lint/type-check and enables Bun tests.
edge-apps/powerbi/index.html Switches to TS module entrypoint.
edge-apps/powerbi/bun.lock Updates lockfile for new tooling/testing dependencies.
edge-apps/powerbi/.gitignore Ignores node_modules/ and dist/.

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

Comment thread edge-apps/powerbi/src/utils.ts Outdated
Comment thread edge-apps/powerbi/src/services.ts Outdated
Comment thread edge-apps/powerbi/index.html
- Updated the embed token return to handle null expiration values.
- Added eslint-disable comments for functions exceeding max lines in tests.
- Cleaned up the index.html by removing duplicate script tag.
@rusko124 rusko124 marked this pull request as ready for review June 17, 2026 12:01
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants