@webority/web-core 0.169.1 → 0.170.1

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.
package/README.md CHANGED
@@ -348,8 +348,8 @@ const file = await downloadFileResumable(userClient, {
348
348
  - A cross-origin API must list `Content-Range`, `ETag`, `Last-Modified` and `Content-Disposition` in
349
349
  `Access-Control-Expose-Headers`. Without `Content-Range` the browser hides it and the first chunk
350
350
  already fails with `download_range_invalid`.
351
- - Known gap: an empty (zero-byte) file cannot be fetched this way yet; use `downloadFile` for
352
- a file that can be empty.
351
+ - An empty file comes back as an empty `blob`: the server answers the first request `416` with
352
+ `Content-Range: bytes */0`, which counts as a finished download.
353
353
 
354
354
  ## Storage
355
355
 
@@ -1 +1 @@
1
- import{extractApiError as e}from"../errors/extractApiError.js";import{readBlobErrorBody as t}from"./blobErrorBody.js";import{contentDispositionFileName as n}from"./downloadFile.js";var r=4194304,i=`download_range_invalid`,a=`The download could not be continued. Please try again.`,o=()=>({chunks:[],received:0,total:null,validator:null,fileName:null,contentType:``}),s=e=>{e.chunks=[],e.received=0,e.total=null,e.validator=null,e.fileName=null,e.contentType=``},c=(e,t)=>{if(typeof e==`object`&&e)return`get`in e&&typeof e.get==`function`?e.get.call(e,t):Reflect.get(e,t)},l=e=>({code:i,message:a,fieldErrors:{},status:0,offline:!1,traceId:null,diagnostic:e,extensions:{}}),u=/^bytes (\d+)-(\d+)\/(\d+)$/i,d=e=>{if(typeof e!=`string`)return null;let t=u.exec(e);if(t===null)return null;let n=Number(t[1]),r=Number(t[2]),i=Number(t[3]);return[n,r,i].every(e=>Number.isSafeInteger(e))?{start:n,end:r,total:i}:null},f=e=>{let t=c(e,`etag`);if(typeof t==`string`&&t!==``&&!t.startsWith(`W/`))return t;let n=c(e,`last-modified`);return typeof n==`string`&&n!==``?n:null},p=e=>{let t=c(e,`content-disposition`);return typeof t==`string`?n(t):null},m=async(n,i)=>{let{resume:a,chunkBytes:o=r,onProgress:u,signal:m,...h}=i;if(!Number.isSafeInteger(o)||o<1)throw RangeError(`downloadFileResumable: chunkBytes must be a positive integer.`);for(;a.total===null||a.received<a.total;){let r=a.received,i=r>0&&a.validator!==null?{"If-Range":a.validator}:{},g={...h.headers,Range:`bytes=${r}-${r+o-1}`,...i},_;try{_=await n.request({...h,headers:g,responseType:`blob`,...m===void 0?{}:{signal:m},...u===void 0?{}:{onDownloadProgress:e=>u(r+e.loaded,a.total)}})}catch(n){await t(n);let r=e(n);throw r.status===416&&s(a),r}let v=_.data;if(!(v instanceof Blob))throw l(`"${h.url??``}" answered without a file body.`);if(_.status===206){let e=d(c(_.headers,`content-range`));if(e===null)throw l(`Content-Range missing or unreadable (a cross-origin server must expose it).`);if(e.start!==r)throw l(`asked for byte ${r}, got ${e.start}.`);if(v.size===0)throw l(`an empty range answer.`);if(v.size!==e.end-e.start+1)throw l(`the body length does not match Content-Range.`);r===0&&(a.validator=f(_.headers),a.contentType=v.type,a.fileName=p(_.headers)),a.total=e.total,a.chunks.push(v),a.received+=v.size}else s(a),a.chunks.push(v),a.received=v.size,a.total=v.size,a.contentType=v.type,a.validator=f(_.headers),a.fileName=p(_.headers);u?.(a.received,a.total)}let g={blob:new Blob(a.chunks,{type:a.contentType}),fileName:a.fileName};return s(a),g};export{r as DEFAULT_DOWNLOAD_CHUNK_BYTES,i as DOWNLOAD_RANGE_INVALID_CODE,a as DOWNLOAD_RANGE_INVALID_MESSAGE,o as createDownloadResume,m as downloadFileResumable};
1
+ import{extractApiError as e}from"../errors/extractApiError.js";import{readBlobErrorBody as t}from"./blobErrorBody.js";import{contentDispositionFileName as n}from"./downloadFile.js";import{isAxiosError as r}from"axios";var i=4194304,a=`download_range_invalid`,o=`The download could not be continued. Please try again.`,s=()=>({chunks:[],received:0,total:null,validator:null,fileName:null,contentType:``}),c=e=>{e.chunks=[],e.received=0,e.total=null,e.validator=null,e.fileName=null,e.contentType=``},l=(e,t)=>{if(typeof e==`object`&&e)return`get`in e&&typeof e.get==`function`?e.get.call(e,t):Reflect.get(e,t)},u=e=>({code:a,message:o,fieldErrors:{},status:0,offline:!1,traceId:null,diagnostic:e,extensions:{}}),d=/^bytes (\d+)-(\d+)\/(\d+)$/i,f=e=>{if(typeof e!=`string`)return null;let t=d.exec(e);if(t===null)return null;let n=Number(t[1]),r=Number(t[2]),i=Number(t[3]);return[n,r,i].every(e=>Number.isSafeInteger(e))?{start:n,end:r,total:i}:null},p=e=>{let t=l(e,`etag`);if(typeof t==`string`&&t!==``&&!t.startsWith(`W/`))return t;let n=l(e,`last-modified`);return typeof n==`string`&&n!==``?n:null},m=e=>{let t=l(e,`content-disposition`);return typeof t==`string`?n(t):null},h=async(n,a)=>{let{resume:o,chunkBytes:s=i,onProgress:d,signal:h,...g}=a;if(!Number.isSafeInteger(s)||s<1)throw RangeError(`downloadFileResumable: chunkBytes must be a positive integer.`);for(;o.total===null||o.received<o.total;){let i=o.received,a=i>0&&o.validator!==null?{"If-Range":o.validator}:{},_={...g.headers,Range:`bytes=${i}-${i+s-1}`,...a},v;try{v=await n.request({...g,headers:_,responseType:`blob`,...h===void 0?{}:{signal:h},...d===void 0?{}:{onDownloadProgress:e=>d(i+e.loaded,o.total)}})}catch(n){await t(n);let a=e(n),s=r(n)?n.response?.headers:void 0,u=l(s,`content-range`);if(a.status===416&&i===0&&typeof u==`string`&&/^bytes \*\/0$/i.test(u))return d?.(0,0),c(o),{blob:new Blob([],{type:``}),fileName:m(s)};throw a.status===416&&c(o),a}let y=v.data;if(!(y instanceof Blob))throw u(`"${g.url??``}" answered without a file body.`);if(v.status===206){let e=f(l(v.headers,`content-range`));if(e===null)throw u(`Content-Range missing or unreadable (a cross-origin server must expose it).`);if(e.start!==i)throw u(`asked for byte ${i}, got ${e.start}.`);if(y.size===0)throw u(`an empty range answer.`);if(y.size!==e.end-e.start+1)throw u(`the body length does not match Content-Range.`);i===0&&(o.validator=p(v.headers),o.contentType=y.type,o.fileName=m(v.headers)),o.total=e.total,o.chunks.push(y),o.received+=y.size}else c(o),o.chunks.push(y),o.received=y.size,o.total=y.size,o.contentType=y.type,o.validator=p(v.headers),o.fileName=m(v.headers);d?.(o.received,o.total)}let _={blob:new Blob(o.chunks,{type:o.contentType}),fileName:o.fileName};return c(o),_};export{i as DEFAULT_DOWNLOAD_CHUNK_BYTES,a as DOWNLOAD_RANGE_INVALID_CODE,o as DOWNLOAD_RANGE_INVALID_MESSAGE,s as createDownloadResume,h as downloadFileResumable};
@@ -1,4 +1,4 @@
1
- import type { AxiosInstance, AxiosRequestConfig } from "axios";
1
+ import { type AxiosInstance, type AxiosRequestConfig } from "axios";
2
2
  import { type DownloadedFile } from "./downloadFile";
3
3
  export declare const DEFAULT_DOWNLOAD_CHUNK_BYTES: number;
4
4
  export declare const DOWNLOAD_RANGE_INVALID_CODE = "download_range_invalid";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webority/web-core",
3
- "version": "0.169.1",
3
+ "version": "0.170.1",
4
4
  "description": "Platform layer for Webority React web portals: HTTP clients with single-flight token refresh, auth store, API error extraction, RTK Query base query, logger, formatters, storage, version check and route guards. No UI.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "type": "module",
@@ -110,7 +110,7 @@
110
110
  },
111
111
  "sideEffects": false,
112
112
  "dependencies": {
113
- "@webority/api-contract": "0.169.1"
113
+ "@webority/api-contract": "0.170.1"
114
114
  },
115
115
  "peerDependencies": {
116
116
  "@microsoft/applicationinsights-web": "^3.4.5",
@@ -137,7 +137,7 @@
137
137
  "@types/node": "25.6.0",
138
138
  "@types/react": "^19.3.0",
139
139
  "@vitest/coverage-v8": "5.1.0",
140
- "@webority/biome-config": "0.169.1",
140
+ "@webority/biome-config": "0.170.1",
141
141
  "axios": "^1.18.0",
142
142
  "jsdom": "30.1.1",
143
143
  "react": "^19.3.1",