Shared business logic for Scrobbler for Discogs (web & mobile)
npm install scrobbler-for-discogs-libsShared business logic, utilities, and services for both web and mobile versions of Scrobbler for Discogs.
types.ts) - All TypeScript interfaces and typesqueueUtils - 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 generationappleMusic/* - Apple Music metadata fetchingmusicbrainz/* - MusicBrainz metadata fetching- CryptoAdapter - HMAC-SHA1 and MD5 hashing
- StorageAdapter - Persistent storage (localStorage/AsyncStorage)
typescript
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) => / ... /
};
`$3
`typescript
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
`bash
Build the library
npm run buildWatch for changes
npm run watch
`Code Reusability
- ~85% of business logic is shared
- Platform adapters handle web vs mobile differences
- Single source of truth for algorithms and utilities
Architecture Benefits
1. Maintainability - Fix bugs in one place
2. Consistency - Same logic on web and mobile
3. Type Safety - Shared TypeScript types
4. Testability - Test business logic once
5. Bundle Optimization - Tree-shakeable exports
CI/CD
$3
The library uses GitHub Actions for continuous integration:
- Workflow:
.github/workflows/build.yml
- Triggers: Push/PR to main or develop branches
- Node versions: Tests on Node 20.x and 22.x
- Steps:
1. Checkout code
2. Install dependencies with npm ci
3. Build library with npm run build
4. Verify build artifacts (dist/index.js, dist/index.d.ts)
5. Upload artifacts (Node 22.x only)$3
`markdown
!Build Status
``Both web and mobile app repositories have their own GitHub Actions workflows that:
1. Check out the app repository
2. Check out the shared library repository
3. Build the shared library
4. Install and link the library locally
5. Build and test the app
This ensures that changes to the shared library don't break dependent applications.