@screenly/edge-apps
v1.1.0
Published
A TypeScript library for interfacing with Screenly Edge Apps API
Readme
@screenly/edge-apps
A TypeScript library for interfacing with the Screenly Edge Apps API.
Installation
[!NOTE] Requires Node.js >= 20.6.0.
npm install @screenly/edge-appsOr with Bun:
bun add @screenly/edge-appsLocal Development Setup
When developing Edge Apps locally using the library from this repository, you should link the package.
First, in the root of this repository:
npm install
npm run build
npm linkThen in your Edge App directory:
cd /path/to/your-edge-app
npm link @screenly/edge-appsTo unlink the package when you're done with local development, run the following in your Edge App directory:
npm installQuick Start
import { setupTheme, signalReady, getMetadata } from '@screenly/edge-apps'
setupTheme()
const metadata = getMetadata()
signalReady()Core Functions
Theme & Branding
setupTheme()- Apply theme colors to CSS custom propertiessetupBrandingLogo()- Fetch and process branding logosetupBranding()- Setup complete branding (colors and logo)
Settings
getSettings()- Get all settingsgetSetting<T>(key)- Get specific setting with type safetygetSettingWithDefault<T>(key, default)- Get setting with fallbacksignalReady()- Signal app is ready for display
Metadata
getMetadata()- Get all screen metadatagetScreenName()getHostname()getLocation()getScreenlyVersion()getTags()hasTag(tag)getFormattedCoordinates()getHardware()- Get hardware type asHardwareenum (Anywhere,RaspberryPi, orScreenlyPlayerMax)
Location & Localization
getTimeZone()- Get timezone from GPS coordinatesgetLocale()- Get locale from locationformatCoordinates(coords)- Format coordinates as stringformatLocalizedDate(date, locale)- Format date for localeformatTime(date, locale, timezone)- Format time for localegetLocalizedDayNames(locale)- Get day names for localegetLocalizedMonthNames(locale)- Get month names for localedetectHourFormat(locale)- Detect 12h/24h format for locale
UTM Tracking
addUTMParams(url, params?)- Add UTM parameters to URLaddUTMParamsIf(url, enabled, params?)- Conditionally add UTM parameters
Web Components
This library includes reusable web components for building consistent Edge Apps. See the components documentation for usage details.
Edge Apps Scripts CLI
This package provides the edge-apps-scripts CLI tool for running shared development commands across all Edge Apps. It includes centralized ESLint configuration to avoid duplication.
Available Commands
Development Server
Start the Vite development server with mock data from screenly.yml and mock-data.yml:
npm run devBuilding
npm run buildLinting
To lint your Edge App:
npm run lintTo lint and automatically fix issues:
npm run lint -- --fixType Checking
Run TypeScript type checking:
npm run type-checkCommand-Line Utilities for Edge Apps
- This library provides utilities to help with common Edge App tasks.
- The CLI uses the shared ESLint configuration from
@screenly/edge-apps, so you don't need to maintain your owneslint.config.ts - The build commands assume your Edge App has
index.htmlas the entry point - Build output will be generated in the
dist/directory
It is recommended to add the following scripts to your Edge App's package.json:
{
"scripts": {
"dev": "edge-apps-scripts dev",
"build": "edge-apps-scripts build",
"build:dev": "edge-apps-scripts build:dev",
"lint": "edge-apps-scripts lint",
"type-check": "edge-apps-scripts type-check",
"deploy": "npm run build && screenly edge-app deploy --path=dist/"
}
}[!NOTE] Feel free to customize the scripts as needed for your Edge App. You could also define your own configs like
eslint.config.ts,tsconfig.json, orvite.config.tsif you need more control.
Testing
import { setupScreenlyMock, resetScreenlyMock } from '@screenly/edge-apps/test'
beforeEach(() => {
setupScreenlyMock({ screen_name: 'Test Screen' }, { theme: 'dark' })
})
afterEach(() => {
resetScreenlyMock()
})Types
import type {
Hardware,
ScreenlyMetadata,
ScreenlySettings,
ScreenlyObject,
ThemeColors,
BrandingConfig,
UTMParams,
} from '@screenly/edge-apps'Development
npm install # Install dependencies
npm test # Run tests
npm run build # Build library