scrobbler-for-discogs-libs
v1.0.0
Published
Shared business logic for Scrobbler for Discogs (web & mobile)
Maintainers
Readme
Scrobbler for Discogs - Shared Library
Shared business logic, utilities, and services for both web and mobile versions of Scrobbler for Discogs.
What's Included
✅ 100% Shared Code
- Types (
types.ts) - All TypeScript interfaces and types - Utilities:
queueUtils- Track preparation, timestamp calculationcollectionUtils- Metadata correction logiccollectionSyncUtils- Collection mergingformattingUtils- Artist name formattingfuzzyUtils- Fuzzy search algorithms (Levenshtein distance)sortCollection- Collection sorting with multiple optionscredentialsUtils- Last.fm signature generation
- Services:
appleMusic/*- Apple Music metadata fetchingmusicbrainz/*- MusicBrainz metadata fetching
🔌 Platform Adapters (Interfaces Only)
The library defines interfaces that must be implemented by each platform:
- CryptoAdapter - HMAC-SHA1 and MD5 hashing
- StorageAdapter - Persistent storage (localStorage/AsyncStorage)
Usage
In Web App
import { queueUtils, fuzzySearch, CryptoAdapter } from 'scrobbler-for-discogs-libs';
// Provide web-specific crypto implementation
const webCrypto: CryptoAdapter = {
hmacSha1Base64: (msg, key) => CryptoJS.HmacSHA1(msg, key).toString(CryptoJS.enc.Base64),
md5: (msg) => CryptoJS.MD5(msg).toString(),
rfc3986encode: (str) => /* ... */
};In Mobile App
import { queueUtils, fuzzySearch, CryptoAdapter } from 'scrobbler-for-discogs-libs';
import CryptoJS from 'crypto-js';
// Provide React Native crypto implementation
const mobileCrypto: CryptoAdapter = {
hmacSha1Base64: (msg, key) => CryptoJS.HmacSHA1(msg, key).toString(CryptoJS.enc.Base64),
md5: async (msg) => await Crypto.digestStringAsync(Crypto.CryptoDigestAlgorithm.MD5, msg),
rfc3986encode: (str) => /* ... */
};Development
# Build the library
npm run build
# Watch for changes
npm run watchCode Reusability
- ~85% of business logic is shared
- Platform adapters handle web vs mobile differences
- Single source of truth for algorithms and utilities
Architecture Benefits
- Maintainability - Fix bugs in one place
- Consistency - Same logic on web and mobile
- Type Safety - Shared TypeScript types
- Testability - Test business logic once
- Bundle Optimization - Tree-shakeable exports
CI/CD
GitHub Actions
The library uses GitHub Actions for continuous integration:
- Workflow:
.github/workflows/build.yml - Triggers: Push/PR to
mainordevelopbranches - Node versions: Tests on Node 20.x and 22.x
- Steps:
- Checkout code
- Install dependencies with npm ci
- Build library with npm run build
- Verify build artifacts (dist/index.js, dist/index.d.ts)
- Upload artifacts (Node 22.x only)
Status Badge
Web and Mobile App CI
Both web and mobile app repositories have their own GitHub Actions workflows that:
- Check out the app repository
- Check out the shared library repository
- Build the shared library
- Install and link the library locally
- Build and test the app
This ensures that changes to the shared library don't break dependent applications.
