@scalemule/nextjs 0.1.56 → 0.1.58

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ "use strict";(()=>{var A=i=>JSON.stringify([i.publicationId,i.id]),p=i=>JSON.stringify([i.storyId??A(i),i.revision??""]);var r=i=>typeof i=="number"&&Number.isFinite(i);function b(i){if(typeof i!="string"||i.length>4096)return!1;try{let t=new URL(i);return(t.protocol==="https:"||t.protocol==="http:")&&!t.username&&!t.password}catch{return!1}}function w(i){if(!i||typeof i!="object")return!1;let t=i;return[t.id,t.publicationId,t.title].every(e=>typeof e=="string"&&e.length>0&&e.length<=1e3)&&(t.publicationName===void 0||typeof t.publicationName=="string"&&t.publicationName.length<=1e3)&&b(t.articleUrl)&&[t.storyId,t.revision,t.section,t.publishedAt].every(e=>e===void 0||typeof e=="string"&&e.length<=4096)&&(t.durationSeconds===void 0||r(t.durationSeconds)&&t.durationSeconds>0&&t.durationSeconds<=86400)&&(t.automatic===void 0||typeof t.automatic=="boolean")}function c(i){if(!i||typeof i!="object")return!1;let t=i;return w(t.track)&&r(t.position)&&t.position>=0&&r(t.duration)&&t.duration>=0&&r(t.updatedAt)&&t.updatedAt>=0&&t.updatedAt<=Date.now()+6e4&&[t.completedAt,t.skippedAt].every(e=>e===void 0||r(e)&&e>0)&&Array.isArray(t.ranges)&&t.ranges.length<=100&&t.ranges.every(e=>Array.isArray(e)&&e.length===2&&r(e[0])&&r(e[1])&&e[0]>=0&&e[1]>=e[0]&&e[1]<=t.duration+1)}function m(i){let t=[];for(let[e,n]of i.sort((s,o)=>s[0]-o[0])){let s=t.at(-1);s&&e<=s[1]+.1?s[1]=Math.max(s[1],n):t.push([e,n])}return t.slice(-100)}function d(i){if(!i||typeof i!="object")return!1;let t=i;return t.version===1&&Number.isFinite(t.rate)&&t.rate>=.5&&t.rate<=3&&typeof t.autoplayNext=="boolean"&&typeof t.allowRepeats=="boolean"&&Number.isFinite(t.historyClearedAt)&&t.historyClearedAt>=0&&t.historyClearedAt<=Date.now()+6e4&&Number.isFinite(t.settingsUpdatedAt)&&t.settingsUpdatedAt>=0&&t.settingsUpdatedAt<=Date.now()+6e4&&Array.isArray(t.history)&&t.history.length<=500&&t.history.every(c)}function y(i,t){let e=Math.max(i.historyClearedAt,t.historyClearedAt),n=new Map;for(let s of[...t.history,...i.history]){if(s.updatedAt<=e)continue;let o=p(s.track),a=n.get(o);if(!a)n.set(o,s);else{let l=s.updatedAt>=a.updatedAt?s:a;n.set(o,{...l,ranges:m([...a.ranges,...s.ranges]).filter(f=>f[1]<=l.duration+1),...a.completedAt||s.completedAt?{completedAt:Math.max(a.completedAt??0,s.completedAt??0)}:{}})}}return{...t.settingsUpdatedAt>i.settingsUpdatedAt?t:i,historyClearedAt:e,history:[...n.values()].sort((s,o)=>o.updatedAt-s.updatedAt).slice(0,500)}}var g=document.currentScript,u=g?.dataset.network,h=new Set((g?.dataset.origins??"").split(" ").filter(Boolean));if(u&&h.size){let i=`scalemule:listening-hub:${u}:v1`;window.addEventListener("message",t=>{if(t.source!==window.parent||!h.has(t.origin))return;let e=t.data;if(!e||e.type!=="SM_LISTENING_SYNC"||e.networkId!==u||typeof e.requestId!="string"||e.requestId.length>100||e.memory!==void 0&&(!d(e.memory)||!e.memory.history.every(s=>h.has(new URL(s.track.articleUrl).origin))))return;let n=null;try{let s=JSON.parse(localStorage.getItem(i)??"null");d(s)&&(n=s),e.memory&&(n=n?y(n,e.memory):e.memory,localStorage.setItem(i,JSON.stringify(n)))}catch{}t.source?.postMessage({type:"SM_LISTENING_STATE",networkId:u,requestId:e.requestId,memory:n},{targetOrigin:t.origin})})}})();
@@ -103,10 +103,10 @@ Keep the existing article body with `id="article-narration-body"`. Mounting an
103
103
  article never selects or starts its audio. Listen selects it; Add to queue
104
104
  appends without interrupting playback. Identity is `(publicationId, id)` so IDs
105
105
  in different publications do not collide. The queue deduplicates entries and
106
- holds up to 100 articles. Finishing an article advances to the next one.
106
+ holds up to 100 articles. Finishing removes the article from the queue and advances when autoplay-next is enabled. Actual played ranges must cover at least 90% of the recording before it is marked listened; seeking to the end alone does not count.
107
107
  Unavailable audio stops with a retry/choose-another message.
108
108
 
109
- The compact bar exposes a playback-speed shortcut (cycles upward through the available rates, then resets to 1×), a Follow along toggle, and a Close player button. Closing stops playback, clears the listening queue and active highlights, and dismisses the player. Readers can reopen it with any article’s Listen to this story control. The expanded Speed selector retains all rates, including 0.5× and 0.75×. The player highlighting shortcut is enabled only when the active article has mounted narration controls in this document; it shares the article toggle’s preference.
109
+ The compact bar exposes a playback-speed shortcut (cycles upward through the available rates, then resets to 1×), a Follow along toggle, and a Close player button. Closing pauses playback, preserves the listening queue and position, clears active highlights, and dismisses the player. Clearing the queue is a separate explicit action. Readers can reopen it with any article’s Listen to this story control. The expanded Speed selector retains all rates, including 0.5× and 0.75×. The player highlighting shortcut is enabled only when the active article has mounted narration controls in this document; it shares the article toggle’s preference.
110
110
 
111
111
  `useArticleNarration(track, narration)` attaches the same behavior to custom
112
112
  controls. Highlighting is opt-in, applies only to the active article, clears
@@ -224,3 +224,37 @@ Browser references: [window.open](https://developer.mozilla.org/en-US/docs/Web/A
224
224
  [postMessage](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage),
225
225
  [BroadcastChannel/storage partitioning](https://developer.mozilla.org/en-US/docs/Web/API/Broadcast_Channel_API),
226
226
  [autoplay policy](https://developer.mozilla.org/en-US/docs/Web/Media/Guides/Autoplay).
227
+
228
+ ## Listening memory and catch-up queues
229
+
230
+ Pass `persistence={{storageKey, networkId, hubUrl, allowedOrigins}}` to opt into
231
+ first-party localStorage for speed, queue, resume positions, autoplay and repeat
232
+ preferences, and up to 500 history records. Restore is always paused. Use a
233
+ network/reader-scoped key; clear or change it when changing account scope. Storage
234
+ failure never prevents playback. This is browser memory, not account/cloud sync.
235
+
236
+ The existing consent iframe can load the package's `@scalemule/nextjs/listening-hub.js`
237
+ asset using a script with `data-network` and an exact space-separated `data-origins`
238
+ allowlist. The independent `SM_LISTENING_SYNC` protocol never changes cookie consent.
239
+ It merges newer preferences and per-story history (including clear-history tombstones),
240
+ not active queue ownership. Both sides check origin, window source, namespace and
241
+ payload shape. Signed media URLs and account credentials are never sent or persisted.
242
+ Modern browser partitioning can isolate this hub per top-level site. Local memory
243
+ remains available, and clicks to allowlisted network sites carry only `sm_audio_rate`,
244
+ which is consumed and removed from the destination URL. No extra player is required.
245
+ An iframe cannot guarantee anonymous cross-site history in every browser or sync devices.
246
+
247
+ Supply `loadRecommendations(signal)` returning authorized public track metadata to
248
+ enable the 5/10/20-minute catch-up builder in `ListeningLibrary` (also included beneath
249
+ article controls). `storyId` identifies syndicated editions; `revision` is an explicit
250
+ editorial update, never a generic database modification timestamp. `durationSeconds`
251
+ is the actual recording length. Manual choices stay ahead of future automatic choices;
252
+ recommendations favor unheard stories, alternate available sections, honor saved speed,
253
+ and avoid skipped stories for 24 hours. Repeats are opt-in and only considered once no
254
+ unheard candidates remain. Sessions are finite and can be previewed before playing.
255
+ Finished recordings appear under Recently listened with Replay and Clear listening history.
256
+
257
+ The publication adapter must load recommendations from its own authorized application;
258
+ the client never selects a tenant or supplies arbitrary fetch destinations. Missing
259
+ recordings are excluded. A failed inventory load is an error, not a claim that the reader
260
+ is caught up. Account synchronization requires a separately authorized network identity.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scalemule/nextjs",
3
- "version": "0.1.56",
3
+ "version": "0.1.58",
4
4
  "description": "ScaleMule SDK for Next.js applications - authentication, storage, and user management",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -46,7 +46,8 @@
46
46
  "import": "./dist/audio.mjs",
47
47
  "require": "./dist/audio.js"
48
48
  },
49
- "./audio.css": "./dist/audio.css"
49
+ "./audio.css": "./dist/audio.css",
50
+ "./listening-hub.js": "./dist/listening-hub.global.js"
50
51
  },
51
52
  "files": [
52
53
  "dist",